appended crontab entries with py script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rbt

    #1

    appended crontab entries with py script

    How can I safely append a crontab entry to a crontab file
    progammatically with Python?

    I need to handle crontabs that currently have entries and crontabs that
    are empty. Also, I'd like this to work across Linux and BSD systems.

    Any pointers?
  • Mike Meyer

    #2
    Re: appended crontab entries with py script

    rbt <rbt@athop1.ath .vt.edu> writes:
    [color=blue]
    > How can I safely append a crontab entry to a crontab file
    > progammatically with Python?[/color]

    Well, one way would be to invoke the system crontab utility and use an
    "editor" that passes the file to your program, and reads the results
    back.
    [color=blue]
    > I need to handle crontabs that currently have entries and crontabs that
    > are empty. Also, I'd like this to work across Linux and BSD systems.
    >
    > Any pointers?[/color]

    I think most Free Unix systems use the Vixie cron, and the non-free
    ones have a "crontab" command (do some of them call it cron?) with the
    same API. So you're pretty safe using that.

    If you want to assume that you're going to have the vixie cron, you
    could dig into it's guts to see what it does for locking, and do that
    by hand.

    <mike
    --
    Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

    Comment

    • rbt

      #3
      Re: appended crontab entries with py script

      On Tue, 2005-09-13 at 23:18 -0400, Mike Meyer wrote:[color=blue]
      > rbt <rbt@athop1.ath .vt.edu> writes:
      >[color=green]
      > > How can I safely append a crontab entry to a crontab file
      > > progammatically with Python?[/color]
      >
      > Well, one way would be to invoke the system crontab utility and use an
      > "editor" that passes the file to your program, and reads the results
      > back.
      >[color=green]
      > > I need to handle crontabs that currently have entries and crontabs that
      > > are empty. Also, I'd like this to work across Linux and BSD systems.
      > >
      > > Any pointers?[/color]
      >
      > I think most Free Unix systems use the Vixie cron, and the non-free
      > ones have a "crontab" command (do some of them call it cron?) with the
      > same API. So you're pretty safe using that.
      >
      > If you want to assume that you're going to have the vixie cron, you
      > could dig into it's guts to see what it does for locking, and do that
      > by hand.
      >
      > <mike[/color]

      Here's what I did... can you write uglier code than this ;)

      Works on Mac and Linux... for the most part.

      def add_cron_entry( ):
      home = os.path.expandu ser('~')
      cur_cron = os.popen('cront ab -l > current_crontab .txt')
      cur_cron.read()
      cur_cron.close( )
      fp = file('current_c rontab.txt', 'a')
      print >> fp, "0 * * * * %s/.theft_recovery .py" %home
      fp.close()
      load = os.popen('cront ab current_crontab .txt')
      load.read()
      load.close()

      Comment

      • rbt

        #4
        win32 service and time.sleep()

        I have a win32 service written in Python. It works well. It sends a
        report of the status of the machine via email periodically. The one
        problem I have is this... while trying to send an email, the script
        loops until a send happens and then it breaks. Should it be unable to
        send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
        tries again. This is when the problem occurs. I can't stop the service
        while the program is sleeping. When I try, it just hangs until a reboot.
        Can some suggest how to fix this?

        Thanks,
        rbt

        Comment

        Working...