The method of realizing second-level scheduled tasks with Linux Crontab Shell script
First, write Shell script crontab.sh
#! / bin/bash step=1 # interval cannot be greater than 60 for ((I = 0; I < 60; I = (i+step)); do $(php' / home/www/php/crontab/crontab.php') sleep $step done exit 0
Second, crontab-e enter the following statement, and then: wq save exit
# m h dom mon dow command * / home/www/php/crontab/crontab.sh
Implementation of linux second-level timing task
Train of thought:
Linux itself does not support second-level timing. To implement it, you can run a script regularly (for example, once per minute). The content of this script is actually an endless loop to execute code, that is, to execute all the time.
Note: if a timed program consumes too much time at a time, for example, if you don't play for 1 second, you need to seelp, that is, let the script sleep for a while during the endless loop.
The following shows a second-level scheduled task of a shell script:
1.crontab-e executes inviteFriend.sh scripts every minute
Run in # 2 seconds-invite friends 3.0
* / webservice/crontab/inviteFriend.sh
Change 2.cd / webservice/crontab/ to vim inviteFriend.sh under the directory
Write the following:
#! / bin/bashstep=2 # interval cannot be greater than 60 for ((I = 0; I < 60; I = (i+step)); do # $(php' / home/php/crontab/tolog.php') curl-I http://******.com/InviteFriends/sendInviteFriendCoupon sleep $stepdoneexit 0
Wq save exit
Note: authorize the timed script after saving
Chmod 777 filename
Summary
The above is the Linux Crontab Shell script introduced by the editor to achieve a second-level timing task. I hope it will be helpful to you. If you have any questions, you are welcome to leave a message and the editor will reply to you in time!