Ubuntu: How can I copy and backup my cronjobs? [closed]



Question:

Im new in Ubuntu .. and I am wondering how can i access the /var/spool/cron/crontab directory .. I just want to copy my cronjob to /etc/cron.daily .


Solution:1

Although the /var/spool/cron/crontabs/ is not accessible without superuser privileges, you can still access your own crontab using crontab -l:

$ whoami  steeldriver  $ cat /var/spool/cron/crontabs/steeldriver  cat: /var/spool/cron/crontabs/steeldriver: Permission denied  

but

$ crontab -l | tail -1  * * * * * /usr/bin/printenv > $HOME/cronenv  

This is achieved through the magic of sticky bits:

$ ls -ld /var/spool/cron/crontabs/  drwx-wx--T 2 root crontab 4096 Jun  7 19:34 /var/spool/cron/crontabs/  


Solution:2

Whatever system backup you do should include your /var/spool and /etc directories anyway, so there is nothing special you need to do in order to backup your cron tables.

The per-user cron tables are in /var/spool/cron/crontabs/. You do not edit these files directly, instead you use crontab -e to edit them (or crontab -l to view them).

The system-wide cron table is split into multiple files that reside in /etc/cron.d/

The additional directories such as /etc/cron.daily/, /etc/cron.hourly/ and so on do not hold cron tables but instead hold scripts that are called at that frequency by your system cron tables. They are designed to allow packages to drop in tasks to these directories if they need a task run regularly.

If you want to change the user that a cron runs under, the safest way to do it is to crontab -e as the first user, delete the line from their cron table, log in as the second user, crontab -e, and then add the line to that user's cron table.

If you want to place an entry in the system cron table, you could write up a cron table and place it in /etc/cron.d/. Though unless you are installing your own software system-wide, it usually makes sense to stick with the per-user cron tables.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »