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
  • 13,091
  • 29
  • 107
  • 167

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,660
  • 23
  • 25
1

like root:

 echo "30 * * * * /home/my/var/dir/to/script /var/etc/etc/etc/" > /var/spool/cron/crontabs/username
diegueus9
  • 29,351
  • 16
  • 62
  • 74
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
  • 16,435
  • 4
  • 30
  • 34
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,665
  • 16
  • 14
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
  • 5,114
  • 1
  • 56
  • 53