CronTab scheduled task function introduction and examples

Table of contents

Introduction to scheduled tasks

Introduction to scheduled task examples

Set up auto-start at power on

It is not easy to organize, please read it carefully, I hope it will be helpful to you 

If you have any questions about the article, you can send a private message or comment. We will respond promptly online every day. Welcome to give us advice.


Introduction to scheduled tasks

View crontab: crontab -l

Edit crontab: crontab -e

Delete crontab: crontab -r

Start: systemctl start crond.service

Stop: systemctl stop crond.service

Restart: systemctl restart crond.service

Introduction to scheduled task examples

Example 1: Executed at the 3rd and 15th minutes from 8am to 11am

3,15 8-11 * * * command

Example 2: Executed at the 3rd and 15th minutes from 8am to 11am every two days

3,15 8-11 */2 * * command

Example 3: Execution at the 3rd and 15th minutes from 8am to 11am every Monday

3,15 8-11 * * 1 command

Example 4: Restart smb at 21:30 every night

30 21 * * * /etc/init.d/smb restart

Example 5: Restart smb at 4:45 on the 1st, 10th, and 22nd of every month

45 4 1,10,22 * * /etc/init.d/smb restart

Example 6: Restart smb every 30 minutes between 18:00 and 23:00 every day

0,30 18-23 * * * /etc/init.d/smb restart

Example 7: Restart smb every hour

* */1 * * * /etc/init.d/smb restart

Example 8: Restart smb every hour between 11pm and 7am

* 23-7/1 * * * /etc/init.d/smb restart

Example 9: Execute the script in the /etc/cron.hourly directory every hour

01 * * * * root run-parts /etc/cron.hourly

Set up auto-start at power on

# because /etc/rc.d/rc.local

Add the following:

systemctl start crond.service

It is not easy to organize, please read it carefully, I hope it will be helpful to you 

If you have any questions about the article, you can send a private message or comment. We will respond promptly online every day. Welcome to give us advice.

おすすめ

転載: blog.csdn.net/vlogghd/article/details/128318781