Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to scheduled Task crontab in Shell

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The guided crondtab process periodically checks every minute to see if there is a task to be executed, and if there is a task to be executed, it automatically executes it. This article mainly introduces the scheduled task crontab in Shell. If you need it, you can refer to crondtab scheduled task.

Crondtab is a daemon used under linux to periodically execute certain tasks or wait for certain events to be processed. Similar to the scheduled tasks under windows, the crondtab process periodically checks whether there is a task to be executed every minute, and automatically executes it if there is a task to be executed.

How do I get the shell script to be executed regularly every day?

1. Create a new shell script that needs to be executed regularly, in this case, the date.sh script.

#! / bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/binexport PATHecho "hello world" echo -- "endDate= `date +"% Y-%m-%d% H:%M:%S "`echo" ★ [$endDate] Successful "echo" current time ": $(date +"% Y-%m-%d% H:%M:%S ") > > / www/wwwroot/date.txtecho"-- -- "

two。 Add this date.sh script to the scheduled task and simply run the "crontab-e" command to add it.

[root@localhost] # crontab-www/wwwroot/date.sh 1 * / www/wwwroot/date.sh > / dev/null 2 > & 1 * / www/wwwroot/date.sh > > / www/wwwroot/result.txt 2 > & 1 # execute 3010 * / www/wwwroot/date.sh at 10:30 every day

3. Finally, let's take a look at the output file date.txt and the crontab log.

[root@localhost ~] # tail-n 5 / www/wwwroot/date.txt [root@localhost ~] # tail-f / var/log/cron Summary

The above is the scheduled task crontab in Shell introduced by Xiaobian. I hope it will be helpful to you!

The original text is from: https://www.linuxprobe.com/shell-linux-crontab.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report