Results 1 to 6 of 6

Thread: editing cron jobs with a script

  1. #1
    Join Date
    Feb 2007
    Beans
    40

    editing cron jobs with a script

    I want to add/remove cron jobs with a script.

    I can think of one way to do this: crontab -l, edit the output, then add it back with crontab filename

    But this is ugly. Is there a simpler way? Placing files in /etc/cron.d is perfect but unfortunately requires superuser privileges. Any way around this? The man pages don't help, but surely someone else has encountered this problem before?

  2. #2
    Join Date
    Sep 2009
    Beans
    11
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: editing cron jobs with a script

    If you're not averse to Python, take a look at python-crontab, located at https://launchpad.net/python-crontab.

  3. #3
    Join Date
    Sep 2009
    Location
    Freiburg/Germany
    Beans
    1,112
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: editing cron jobs with a script

    "crontab -e " uses $EDITOR to edit the file. It has not to be an interactive editor, just set it to a script that takes a file names as argument and modifies that file.

    Or use
    Code:
    crontab -l | some_script | crontab -
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters

  4. #4
    Join Date
    Feb 2007
    Beans
    40

    Re: editing cron jobs with a script

    Thanks for the suggestions. Both are basically the first method I was talking about. I guess there is no alternative.

  5. #5
    Join Date
    Mar 2009
    Location
    S. France or PNW, USA
    Beans
    59
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: editing cron jobs with a script

    It's always possible that what you want to do can be done another way.

    For example, if the object of the cronjob change is a filename substitution, set the cronjob to read the filename from a file.

    Another thing folks often want to do is to control the date or time that a cronjob runs ("every other Friday except on Christmas"), something that you can also do within the cronjob itself.

    So ... aside from the general idea of changing a cronjob with a script, what are you really trying to do?

    -Shel

  6. #6
    Join Date
    Sep 2009
    Location
    Freiburg/Germany
    Beans
    1,112
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: editing cron jobs with a script

    If you want to manage your cronjobs in e.g. ~/.cron.d/, just use something like

    Code:
    cat ~/.cron.d/* | crontab -
    after you modified anything in ~/.cron.d/
    ClassicMenu Indicator - classic GNOME menu for Unity
    Unsettings - configuration program for the Unity
    Privacy Indicator - easily switch privacy settings in Unity
    Arronax - create and modify app starters

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •