3

I would like to add a crontab schedule by doing this in my server:

echo "30 * * * * /home/my/var/dir/to/script /var/etc/etc/etc/" > crontab -e

Is there a way to do this without going doing crontab -e and then typing in the command?

Harry
  • 11,003
  • 22
  • 95
  • 160

5 Answers5

2

Could try

1)nano /etc/crontab (or any other editor, e.g. emacs)
2)echo "30 * * * * /home/my/var/dir/to/script /var/etc/etc/etc/" > /etc/crontab
3)or put the contents of this into a file, then do "file > /etc/crontab"
NT_
  • 2,642
  • 21
  • 25
1

like root:

 echo "30 * * * * /home/my/var/dir/to/script /var/etc/etc/etc/" > /var/spool/cron/crontabs/username
diegueus9
  • 20,833
  • 15
  • 58
  • 73
0

The proper fix is probably to use a file as specified in https://stackoverflow.com/a/4421284/377927, but it is possible to use tee to append a line to the crontab by doing e.g.:

echo "* * * * * ls" | EDITOR="tee -a" crontab -e

tee -a will append stdin to the file it gets specfied, the EDITOR variable tells crontab to use tee -a as editor.

Community
  • 1
  • 1
gauteh
  • 14,017
  • 3
  • 25
  • 32
0

If you have the whole crontab in a text file, you can upload a whole crontab to replace the old crontab by doing:

cat <crontab_text_file> | crontab -

This will wipe out your old crontab. Using '-' allows you to use standard input into the crontab.

sk8asd123
  • 1,465
  • 15
  • 13
0

We have the following setup in production on RHEL: - a custom software starting sh in init.d , which - handles cron start , stop , reload - writes cron tasks into separate tmp file and loads this file with crontab -e

I have been only maintaining it for several months but it works like a charm ...

Yordan Georgiev
  • 4,006
  • 1
  • 43
  • 47