问题
I'm trying to add a line to the crontab on Ubuntu.
Right now, I'm doing crontab -e
and editing the crontab there.
However, I can't seem to find the real crontab file, since crontab -e
seems to give you a temporary working copy.
/etc/crontab
looks like the system crontab.
What is the path of the crontab that crontab -e
saves to?
Thanks!
回答1:
Use crontab -l > file
to list current user's crontab to the file
, and crontab file
, to install new crontab.
回答2:
You can also do it without a temporary file:
(crontab -l ; echo "0 4 * * * myscript")| crontab -
回答3:
If your crontab is empty you should use 2>/dev/null
:
(crontab -l 2>/dev/null; echo "0 4 * * * myscript")| crontab -
回答4:
The user crontab file is in '/var/spool/cron/crontabs' for ubuntu.
adyliu@adyliu-pc:~$ sudo ls -lh /var/spool/cron/crontabs/adyliu
-rw------- 1 adyliu crontab 1.2K 2012-03-01 09:33 /var/spool/cron/crontabs/adyliu
'adyliu' is your login user.
You need root privilege to see this file.
Using "crontab -e" maybe is the best way to modify cron script.
In the manual:
Users are not allowed to edit the files under that directory directly to ensure that only users allowed by the system to run periodic tasks can add them, and only syntactically correct crontabs will be written there.
来源:https://stackoverflow.com/questions/8579330/appending-to-crontab-with-a-shell-script-on-ubuntu