2

This question already has an answer here:

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/'

marked as duplicate by muru, Anthon, jimmij, jordanm, John WH Smith Feb 26 '15 at 20:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @muru that accepted answer is a triple command on two lines (which admittedly could be made into a one-liner). – Anthon Feb 26 '15 at 15:26
  • @Anthon yes, but OP seems capable of adapting it. :) – muru Feb 26 '15 at 15:29
5

You can do it with this:

{ crontab -l; echo "30 23 * * * /path_to/script/"; } | crontab -
  • 2
    Why disturb a cat? { crontab -l; echo "30 23 * * * /path_to/script/"; } | crontab - – muru Feb 26 '15 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 '15 at 14:09
  • @Gabriel The AU command explicitly specifies the user, otherwise there's no difference in effect. – muru Feb 26 '15 at 14:11
  • You're right. Don't disturb the cat. – jcbermu Feb 26 '15 at 14:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.