问题
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?
回答1:
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"
回答2:
like root:
echo "30 * * * * /home/my/var/dir/to/script /var/etc/etc/etc/" > /var/spool/cron/crontabs/username
回答3:
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 ...
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/3186471/crontab-without-crontab-e