1. Whether the query is installed: Rpm-qa|grep cron
2. Install Crontab:
[Root@centos ~]# Yum Install Vixie-cron
[Root@centos ~]# Yum Install Crontabs
Description
Vixie-cron packages are Cron's main programs;
The Crontabs package is a program used to install, uninstall, or enumerate the tables used to drive the cron daemon.
3. Start and close this cron service in the following ways:
/sbin/service crond Start//boot service
/sbin/service Crond Stop//Off service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration
See Crontab Service Status: Service Crond status
Manually start the Crontab service: Service Crond start
To see if the Crontab service is set to boot, execute command: NTSYSV
Join the boot auto start:
Chkconfig–level Crond on
4.cron View log: Cat/var/log/cron
5. Create timed tasks: crontab-e, Edit and save, automatically save to path/var/spool/cron/root (root, automatically named file with current user name):
Executes the ct.sh file in the path/opt/test/every minute
*/1 * * * * sh/opt/test/ct.sh
6./opt/test/ct.sh content:
Implementation features: Under the path "/opt/test" Create a separate year/month/day/Time/Sub-command of the nested folder, in minutes named folder, write a current second named TXT file, the content is the current date time (to seconds), as follows:
#!bin/bash
dr= "/opt/test"
#创建文件夹, ignoring mkdir-p $dr if already existing
$dr
if [!-D $dr];then
mkdir $dr C6/>else
echo "=============== Dr is existed!"
Fi
dy= $dr/$ (date "+%y")
echo "Year dir:" + $dy
mkdir-p $dy
dm= $dy/$ (date "+%m")
mkdir-p $DM
echo "DM dir:" + $dm
dd= $dm/$ (date "+%d")
mkdir-p $dd
echo "dd dir:" + $dd
dh= $dd/$ (date "+%h")
mkdir-p $dh
echo "dh dir:" + $dh
dmm= $dh/$ (date "+%m")
echo "DMM dir:" + $dmm
mkdir-p $dmm
fsec= $dmm/$ (date "+%s"). txt touch
$fsec
(date "+%y%m%d%h%m%s") >> $fsec
The execution effect is as follows: