5

First of all, I'm using elementary OS (based on Ubuntu 12.04).

I have a cron job set up to run a script every day at 23:30:

30 23 * * * /path_to_script/

Is there a way to add it to cron via a single terminal command? All examples I've seen involve invoking cron first via crontab -e and then adding the job there.

I'd like a single command for doing this, something like:

cron add-job '30 23 * * * /path_to_script/'
2
  • @muru that accepted answer is a triple command on two lines (which admittedly could be made into a one-liner).
    – Anthon
    Feb 26, 2015 at 15:26
  • @Anthon yes, but OP seems capable of adapting it. :)
    – muru
    Feb 26, 2015 at 15:29

1 Answer 1

9

You can do it with this:

{ crontab -l; echo "30 23 * * * /path_to/script/"; } | crontab -
4
  • 2
    Why disturb a cat? { crontab -l; echo "30 23 * * * /path_to/script/"; } | crontab -
    – muru
    Feb 26, 2015 at 14:07
  • What is the difference between this command (or the one given by @muru) and: (crontab -u userhere -l; echo "30 23 * * * /path_to/script/" ) | crontab -u userhere - taken from askubuntu.com/questions/58575/add-lines-to-cron-from-script
    – Gabriel
    Feb 26, 2015 at 14:09
  • @Gabriel The AU command explicitly specifies the user, otherwise there's no difference in effect.
    – muru
    Feb 26, 2015 at 14:11
  • You're right. Don't disturb the cat.
    – jcbermu
    Feb 26, 2015 at 14:12

Not the answer you're looking for? Browse other questions tagged .