![]() |
|
|
www.southgatearc.org
|
|
|
Automating Tasks in Linux using CronLinux has a powerful task scheduler called Cron. Cron will allow you
to run commands automatically at times specified by you. Cron is similar
to the task scheduler you find in What's Cron and Crontab ? You must be wondering what the difference between cron and crontab
or whether they are the same. Cron is a process or program which wakes
up every minute and looks for jobs it Crontab Format: Each entry in Crontab has at least 6 fields separated by a single space. Now let's see how to make a crontab entry. Let's say you want to run a script backup.sh every day at 6:00pm.The entry would look like this: 0 18 * * * /home/user/backup.sh The asterisk (*) is used to indicate that every instance of the particular
time period will be used (i.e. every hour, every weekday, etc.). I've
used to full path to the script * Let's schedule the script printinvoices.sh to run every sunday at 12:45pm. 45 12 * * 0 /home/account/printinvoices.sh * How about clearaccount.sh every month beginning at 1:32am ? 21 1 1 * * /home/accont/clearaccount.sh * Let's see how to schedule a task to run only on weekdays(monday to friday) 0 10 * * 1-5 /home/account/cleartemp.sh Adding and Editing Entries in Crontab Now that you know how crontab entries are formated, it's time to put
some of your entries into the crontab list. To do this, you can use
the crontab command. By specifying the -e option, you'll be taken to
the default text editor to add and edit your crontab list. [crontab
-e] Viewing Crontab: [crontab -l] You can view your current crontab list by specifying the -l option. Issuing this command will print out a list of all your current jobs in the crontab list Removing Crontab: [crontab -r] The -r option removes your current crontab file. Issuing this command will empty the contents of the current user's crontab file Output from cron Usually the output of cron gets mailed to the owner of the process
or the person or email id specified in the MAILTO variable. To set the
MAILTO variable, you'll have to add the If you have a command that is run frequently, and you don't want the output to be emailed each time, you can redirect the output to a log file cmd >> log.file, so your job would be something like this. 0 18 * * * /home/user/backup.sh>>log.file If you don't want any output at all, you can redirect the 0 18 * * * /home/user/backup.sh>>/dev/null
|
|
| |
|
| Home
| For
Sale & Wanted | Tell
a friend | Guestbook
| Cast Your Vote | Newsboard
| Amateur Radio
Forum | Links | Diary
Dates | | Games | SWLs | 'How To' Guides | Humour | Data Comms | Lottery | Amateur TV | Contests | Can You Help? | Contact Us | 10 Metres | | Clubs Worldwide | Subscribe to our Newsletter | | |
|
| |