Linux Create timed tasks and date formatting

Source: Internet
Author: User

-----reproduced from the network

1. Create a timed task
$ crontab-u//Set a user's Cron service, the general root user needs this parameter when executing this command $ CRONTAB-E//Edit Task $ crontab-l//show current Task $ crontab-r//Delete all current tasks

Text Format (CRONTAB-E | Cat/etc/crontab)

#.----------------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

Example:

After editing a user's cron settings, Cron automatically generates a file with the same name as the user under/var/spool/cron, and the cron information for this user is recorded in this file, which cannot be edited directly and can only be edited with CRONTAB-E. After Cron starts, read the file once every one of the clocks, and check to see if you want to execute the command inside. Therefore, the Cron service does not need to be restarted after this file has been modified.

2. Format time
#获取昨天日期 yyyyMMdd format yesterday= ' date--date= ' 1 days ago ' +%y%m%d ' #获取昨天日期 yyyy-mm-dd format yesterday2= ' date--date= ' 1 days ago ' +  %y-%m-%d ' #获取今天日期 yyyyMMdd format today= ' date--date= ' 0 days ago ' +%y%m%d ' #获取今天日期 yyyy-mm-dd format today2= ' date--date= ' 0 days ago ' +%y-%m-%d ' #获取明天日期 yyyyMMdd format today= ' date--date= ' 1 days ' +%y%m%d ' #获取明天日期 yyyy-mm-dd format today2= ' date--date= ' 1 days ' +%y-% m-%d ' #获取当前时间 yyyy-mm-dd HH:mm:ss format nowtime= ' date--date= ' 0 days ago ' "+%y-%m-%d%h:%m:%s" ' #获取当前日间 HH:mm:ss format nowtime2= ' Date--date= ' 0 days ago ' +%h:%m:%s ' #获取1小时前时间 yyyy-mm-dd HH:mm:ss format onehourage= ' date--date= ' 1 hours ago ' "+%y-%m-%d%h:%m: %s "' #获取1小时后时间 yyyy-mm-dd HH:mm:ss format onehourage2= ' date--date= ' 1 hours '" +%y-%m-%d%h:%m:%s "' #获取2小时前时间 yyyy-mm-dd hh:mm: SS Format twohourage= ' Date--date= ' 2 hours ago ' "+%y-%m-%d%h:%m:%s" ' #获取2小时后时间 yyyy-mm-dd HH:mm:ss format twohourage2= ' Date--date = ' 2 hours ' "+%y-%m-%d%h:%m:%s" ' #获取1个月前时间 yyyy-mm-dd HH:mm:ss format Date--date= ' 1 month ago ' +%y-%m-%d%h:%m:%s ' #获取1个月加1天前时 Inter yyyy-mm-dd HH:mm:ss Format Date--date= ' 1 month ago + 1 day ago ' "+%y-%m-%d%h:%m:%s" #获取1个月减1天前时间 yyyy-mm-dd HH:mm:ss Format Date--date= ' 1 month ago-1 day ago ' +  %y-%m-%d%h:%m:%s "#获取1个月加1天加1小时加1分钟加1秒钟前时间 yyyy-mm-dd HH:mm:ss Format Date--date= ' 1 month ago + 1 day ago + 1 hour ago + 1 min  ago + 1 sec ago ' "+%y-%m-%d%h:%m:%s" #获取1个月加1天减1小时减1分钟减1秒钟前时间 yyyy-mm-dd HH:mm:ss format can +-abused date--date= ' 1 month ago + 1 day ago-1 hour ago-1 min ago-1 sec ago ' +%y-%m-%d%h:%m:%s ' #获取1个月加1天加1小时加1分钟加1秒钟后时间 yyyy-mm-dd HH:mm:ss format Date- -date= ' 1 month + 1 day + 1 hour + 1 min + 1 sec ' "+%y-%m-%d%h:%m:%s" #获取1个月加1天减1小时减1分钟减1秒钟后时间 yyyy-mm-dd HH:mm:ss format da Te--date= ' 1 month + 1 day-1 hour-1 min-1 sec ' "+%y-%m-%d%h:%m:%s" #获取1年后1个月加1天减1小时减1分钟减1秒钟后时间 yyyy-mm-dd hh:mm: SS Format Date--date= ' 1 year 1 month + 1 day-1 hour-1 min-1 sec ' "+%y-%m-%d%h:%m:%s" #获取1年前1个月加1天减1小时减1分钟减1秒钟后时间 yyy Y-MM-DD HH:mm:ss Format Date--date= ' 1 year 1 month + 1 day-1 hour-1 min-1 sec ' "+%y-%m-%d%h:%m:%s"

Linux Create timed tasks and date formatting

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.