crontab---timed task

crontab—timed task (pronounced: cron table)

1. Main timing tasks

Insert picture description here
/etc/cron.d/ This directory is used to store any crontab files or scripts to be executed.

Two, crontab main commands

crontab -e  # 编辑定时任务
crontab -l  # 表示列出所有的定时任务
crontab -r  # 表示删除用户的定时任务,当执行此命令后,所有用户下面的定时任务会被删除,执行crontab -l后会提示用户:“no crontab for admin”

[Note: 5 stars in timed tasks]

* * * * *
Respectively
Minute, hour, day, month, week

Three, basic timing

Features command
Execute every 1 minute * * * * * myCommand
Executed at the 3rd and 15th minutes of every hour 3,15 * * * * myCommand
Executed at the 3rd and 15th minutes from 8 am to 11 am 3,15 8-11 * * * myCommand
Executed at the 3rd and 15th minutes from 8 am to 11 am every two days 3,15 8-11 */2 * * myCommand
Executed on the 3rd and 15th minutes from 8 am to 11 am every Monday 3,15 8-11 * * 1 myCommand
Restart smb at 21:30 every night 30 21 * * * /etc/init.d/smb restart
Restart smb at 4:45 on the 1, 10, and 22 of each month 45 4 1,10,22 * * /etc/init.d/smb restart
Restart smb at 1:10 every Saturday and Sunday 10 1 * * 6,0 /etc/init.d/smb restart
Restart smb every 30 minutes between 18:00 and 23:00 every day 0,30 18-23 * * * /etc/init.d/smb restart
Restart smb every Saturday at 11: 00 pm 0 23 * * 6 /etc/init.d/smb restart
Restart smb every hour 0 */1 * * * /etc/init.d/smb restart
Between 11pm and 7am, restart smb every hour 0 23-7/1 * * * /etc/init.d/smb restart

Example: output the print result of a function in a shell to another file every minute

After entering the edit mode, output the following code

* * * * * sh /opt/test/func.sh >> /opt/test/a.txt

[Supplement: The function of func.sh is to output hello world]
View the a.txt file under test The
result shows:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43288259/article/details/114839244