Working with the CRON Job Scheduler
Through the console, you can work with the CRON job scheduler using the crontab command:
- To see a list of existing user jobs, use the
crontab -lcommand; - To enter edit mode, use the command
crontab -e.
The list of jobs in the console is displayed as follows:
root@example:~# crontab -l
## Ispmanager update package cache task
26 1 * * * /usr/local/mgr5/sbin/cron-ispmgr sbin/pkgupdate.sh >/dev/null 2>&1
## Ispmanager stat handler (ispmgr)
37 22 * * * /usr/local/mgr5/sbin/cron-ispmgr sbin/mgrctl -m ispmgr ispstat >/dev/null 2>&1
## Ispmanager periodic tasks handler (ispmgr)
* * * * * /usr/local/mgr5/sbin/cron-ispmgr sbin/mgrctl -m ispmgr periodic >/dev/null 2>&1
Each new job usually starts with a schedule in this order: minutes, hours, days of the month, months, and days of the week. After the schedule, the path to the executable file is specified.
In the line above the job itself, you can set a description for it, which is indicated as a comment (a line with ## symbols).
Example
As an example, let's create a job to write the system time to a file every 2 minutes.
Create a file and add the following lines to it using a text editor such as nano:
nano /root/servtimetest
#! /bin/sh
date>> date-out.txt
Specify the correct permissions for the file:
сhmod 775 /root/servtimetest
Go to the CRON Job Edit mode and create a new job:
crontab -e
## save the system_date
*/2 * * * * /root/servtimetest >/dev/null 2>&1
Once the job is saved, every two minutes, the server time will be recorded in the date-out.txt file that will appear next to the script.
You can view the job’s progress in the system log:
/var/log/syslog- for Debian systems;/var/log/messages- for RHEL systems.