Get the App
SLTechnology News&Howtos  ›  Servers  › 

A brief introduction to scheduled Task crontab in Shell

Shulou Source: shulou.com Published: 2022-06-02 06:00:55 11月16日 Update

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

Tags: Tasks scripts processes checks events original text cycles periodicity commands files logs time friends articles references processing help output run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Apple MySQL vpn