Appending to crontab with a shell script on Ubuntu
UbuntuCronDebianCrontabUbuntu Problem Overview
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!
Ubuntu Solutions
Solution 1 - Ubuntu
You can also do it without a temporary file:
(crontab -l ; echo "0 4 * * * myscript")| crontab -
Solution 2 - Ubuntu
Use crontab -l > file
to list current user's crontab to the file
, and crontab file
, to install new crontab.
Solution 3 - Ubuntu
If your crontab is empty you should use 2>/dev/null
:
(crontab -l 2>/dev/null; echo "0 4 * * * myscript")| crontab -
Solution 4 - Ubuntu
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.