Editing users cronjob through ssh

I can see cronjobs owned by root by

crontab -l

You can use following command to see user’s crons

crontab -u username -l

User’s cron jobs reside in /var/spool/cron/ you can see them there also.

You would have to run this as root

for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done

will loop over each user name listing out their crontab. The crontabs are owned by the respective users so you won’t be able to see another user’s crontab w/o being them or root.

 

If you wished to have a script named /root/backup.sh run every day at 3am, your crontab entry would look like as follows. First, install your cronjob by running the following command:
# crontab -e
Append the following entry:
0 3 * * * /root/backup.sh
Save and close the file.

Cron Easy to remember format:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

If you wish to edit a users cronjob, following command would be used :

# crontab -u username -e

This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.