ChatGPT 有多强:用 ChatGPT 十秒学会设置自动任务

From 清冽之泉
Jump to navigation Jump to search
How to write a corntab to run sth.sh at everyday 21:30?
ChatGPT

To schedule a task to run a shell script (sth.sh) every day at 21:30 using a cron job, you can create a cron tab entry. Cron tab entries have the following format:

1* * * * * command_to_be_executed
2- - - - -
3| | | | |
4| | | | +----- Day of the week (0 - 7) (Sunday is both 0 and 7)
5| | | +------- Month (1 - 12)
6| | +--------- Day of the month (1 - 31)
7| +----------- Hour (0 - 23)
8+------------- Minute (0 - 59)

To run sth.sh every day at 21:30, you would set the minute field to 30 and the hour field to 21. The other fields can be set to an asterisk (*) to indicate "any" value. Here's the cron tab entry to achieve this:

30 21 * * * /path/to/sth.sh

Make sure to replace /path/to/sth.sh with the actual path to your sth.sh script. To edit your crontab, you can use the crontab -e command, which opens your default text editor for editing the cron jobs. Add the line mentioned above to schedule your script to run at 21:30 every day, and then save the file.

Remember that the timing of cron jobs is based on your system's local time, so ensure that your system's clock and time zone settings are accurate.