1) Uncomment the #cron line in /etc/syslog.conf to enable cron logging
2) Restart sysklogd : sudo /etc/init.d/sysklogd restart
3) Add cron jobs through crontab -e
4) Restart cron : sudo /etct/init.d/cron restart
To disable email notification, redirect the output to /dev/null
0 3 * * * /root/backup.sh >/dev/null 2>&1
Special strings to substitute * * * * *
Special string | Meaning |
@reboot | Run once, at startup. |
@yearly | Run once a year, "0 0 1 1 *". |
@annually | (same as @yearly) |
@monthly | Run once a month, "0 0 1 * *". |
@weekly | Run once a week, "0 0 * * 0". |
@daily | Run once a day, "0 0 * * *". |
@midnight | (same as @daily) |
@hourly | Run once an hour, "0 * * * *". |
User crontabs are saved in
/var/spool/cron
*Cron status reporting
Set up Evolution to read mails sent by cron.
Create a new account and select "local delivery mails" from the dropdown box. This will enable Evolution to receive mails sent to /var/mail/
*cron commands are also logged in auth.log
Alternative to cron jobs
If a particular task needs to be schedule to be run once or a few times, an alternative solution would be to use the "at" command. This command basically allows the user to schedule a job at any particular time. Eg to send out an email at 4am next week.
at -f /home/user/atcommand -m now + 7 days
The f options tells the at command to run the content of a file (which is in a script format situated at /home/user/atcommand). The -m options will tell the system to send out an email (which contains the output of the command) to notify the user once the job is done and now + 7 days indicates that this job will be executed 7 days from now.
*make sure that there's either /etc/at.deny or /etc/at.allow file in your system. Else, onyl the root will be able to use the at command. These are basically ACL for at command.
You can query all at command jobs using atq and remove the jobs using atrm
Anacron for systems that are not up and running 24/7.
For each job, Anacron checks whether this job has been executed in the last n days, where n is the period specified for that job. If not, Anacron runs the job's shell command, after waiting for the number of minutes specified as the delay parameter.
After the command exits, Anacron records the date in a special timestamp file for that job, so it can know when to execute it again. Only the date is used for the time calculations. The hour is not used.
When there are no more jobs to be run, Anacron exits.
Only root can schedule anacron jobs. A way to enable other users to do so is by creating an anacron group and enable write permission for this group on /var/spool/anacron (where job timestamps are stored)
# run-parts /etc/cron.daily
"run-crons" executes all the scripts in the /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly, and /etc/cron.weekly directories.
*used to find files in directory that is messy, file criteria is *junk*
find /tmp -name '*junk*' -exec ls -l {} \;
To force anacron to be executed hourly, put a script which consist of the following in /etc/cron.hourly
/usr/sbin/anacron -s
No comments:
Post a Comment