How do I make Linux timed tasks crontab in seconds?
Linux scheduled task crontab min execution Time unit is minutes
If you want to execute in seconds, how should you set it?
Ideas
The normal scenario is to define the tasks to be performed directly in crontab, and now we add a script file in the middle
Customize a script file, loop through the tasks you want to perform, and use sleep in the loop to control the number of seconds in intervals
Add a task in Crontab, set to execute this script every minute
is to use crontab to control the minutes, using the loop within the script to control the seconds
Example
(1) Define target tasks
Write a test task in PHP and write a time message to the file
File path/root/test.php
<?php
File_put_contents ('/root/run.log ', date (' y-m-d h:i:s '). " \ r \ n ", file_append);
?>
(2) Writing scripts to perform tasks
File path/root/test.sh
#!/bin/bash
#间隔的秒数, it's going to take a few seconds.
#不能大于60
step=2
for ((i = 0; i <; i= (I+step))); Do
$ (php '/root/test.php ')
Sleep $step
Done
Exit 0
(3) Adding timed tasks
Crontab-e
* * * * * */root/test.sh
Restart Timed Task Service
Service Crond Restart
(4) View effects
Tail-f/root/run.log
You can see that the information is printed by the second
How to make Linux timed tasks crontab in seconds