Linux timed Task Crontab simple example __linux

Source: Internet
Author: User
Tags mkdir
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:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.