Cron

Cron is the daemon that can be used to schedule tasks according to time, day of the month, month, day of the week, and week.

In order to use cron you must have:

1. a package vixie-cron installed.
To check it type:

rpm -q vixie-cron

2. Daemon crond must be running. To check it type:

service crond status

To install crond on Centos type:

yum install vixie-cron

If you want to add some task to cron you must place it in the file

/etc/crontab

Sample crontab config:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
01 00 * * thu,sat root /scripts/./backupvm

Scheduled task is a script ./backupvm which is in folder /scripts. Script is starting as root at 0:01 any day of month, any month, but two days a week: THU an SAT.


On some OS distros you should use

crontab -e

command to edit cron tasks. You can switch to your preferred editor. For example to nano:

EDITOR=nano; export EDITOR

After run again "crontab -e" And place the task. For example we apply to start some script every minute:

* * * * * root /./vpncheck.sh >>/testlog.log

Every 2 minutes:

*/2 * * * * root /./vpncheck.sh >>/testlog.log

Every time when system starts:

@reboot root /./vpncheck.sh >>/testlog.log
 

Was this answer helpful?

 Print this Article

Also Read

NFS on Centos 6

How to install NFS on Centos 6 yum install nfs-utils nfs-utils-lib Set nfs to start...

Backup script sample

#!/bin/bash echo "packing files in progress..." tar -cf /home/backup/root_lib-$(date...

Squid+Privoxy+Tor

How to install squid with tor [NOTE: According to vpsget.com AUP/TOS you can use private proxy...

Generating public/private ssh keys

How to generate and use public / private ssh keys This guide is tested on Centos 6 To...

Oracle 11g EX on Centos 6 x64 vps

We describe how to install Oracle 11g Express on Centos 6 x86_64 Openvz VPS. First of all you...