0

The output of crontab -l and crontab are different.

root@ce:~# crontab -l
0-59 * * * * curl http://ce.scu.ac.ir/courses/admin/cron.php?password=mypass
* * * * * ntpdate –s ir.pool.ntp.org
* * * * * php /var/www/html/shub/ow_cron/run.php
root@ce:~# cat /etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
*/01 * * * *    www-data    /var/www/html/shub/ow_cron/run.php
*/1 * * * *     www-data /usr/bin/php7.0 /var/www/html/courses/admin/cli/cron.php > /var/log/moodle/cron.log
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

I ask that because some documents say to use crontab -e to define cron jobs. Should I use crontab -e or vim /etc/crontab?

3

crontab -l shows the running user's crontab, the one stored in /var/spool/cron/crontabs. Anything defined there runs under the user id of that user. This isn't particular to root, but root can also have one.

/etc/crontab, on the other hand, contains the system-wide main crontab (along with /etc/cron.d). The entries in that file have an additional field for the username, the jobs defined there run under that user id.

You can use either one, or create a file or files to define your cronjobs under /etc/cron.d.

1

/etc/crontab is the systemwide crontab file and should only be used for that purpose. You also need superuser privileges to edit this file.

In addition every user has its own "crontab" for personell use and you can edit this file via the "-e" option as you described.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.