How to implement second-level scheduled tasks with Linux Crontab Shell script

How to implement second-level scheduled tasks with Linux Crontab Shell script

1. Write Shell script crontab.sh

#!/bin/bash 
step=1 #The number of seconds between steps 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

2. Enter the following statement in crontab -e, then press :wq to save and exit

# mh dom monitor command 
* * * * * /home/www/php/crontab/crontab.sh

Linux second-level scheduled task implementation

Ideas:

Linux itself does not support second-level timing. To achieve this, you can run a script at a fixed time (for example, once every minute). The content of this script is actually an infinite loop execution code, that is, it keeps executing.

Note: If the time taken for a scheduled program to execute is too long, for example, it takes more than 1 second to execute, you need to seelp, that is, let the script sleep for a while in the infinite loop.

The following demonstrates a shell script's second-level timing task:

1.crontab -e executes the inviteFriend.sh script every minute

#2 seconds to run - Invite friends 3.0

 * * * * * /webservice/crontab/inviteFriend.sh

2.cd /webservice/crontab/ Switch to the directory vim inviteFriend.sh

Write the following content:

#!/bin/bash
step=2 #The number of seconds between steps 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 $step
done
exit 0

wqSave and exit

Note: After saving, you need to authorize the script.

chmod 777 filename

Summarize

The above is the method that I introduced to you to use Linux Crontab Shell script to implement second-level scheduled tasks. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

You may also be interested in:
  • Implementing web scheduled tasks on AspNet Core
  • How to use crontab to execute a scheduled task once a second in Linux
  • Reasons why crontab scheduled tasks are not executed in Linux
  • Using Crontab to implement PHP script timing tasks under CentOS
  • Detailed explanation of Linux scheduled tasks Crontab (recommended)
  • Detailed explanation of using python crontab to set up Linux scheduled tasks
  • Detailed explanation of implementing crontab-like scheduled tasks in dotnet core

<<:  Mysql keeps the existing content and adds content later

>>:  js to write the carousel effect

Recommend

A brief analysis of the basic implementation of Vue detection data changes

Table of contents 1. Object change detection 2. Q...

Javascript asynchronous programming: Do you really understand Promise?

Table of contents Preface Basic Usage grammar Err...

Detailed explanation of JavaScript's built-in objects Math and strings

Table of contents Math Objects Common properties ...

Disable autocomplete in html so it doesn't show history

The input box always displays the input history wh...

Teach you 10 ways to center horizontally and vertically in CSS (summary)

A must-have for interviews, you will definitely u...

Basic usage examples of Vue named slots

Preface Named slots are bound to elements using t...

Solve the cross-domain problem of get and post requests of vue $http

Vue $http get and post request cross-domain probl...

JS operation object array to achieve add, delete, modify and query example code

1. Introduction Recently, I helped a friend to ma...

MySQL study notes on handling duplicate data

MySQL handles duplicate data Some MySQL tables ma...

MySQL merges multiple rows of data based on the group_concat() function

A very useful function group_concat(), the manual...

MySQL 5.7.17 winx64 installation and configuration graphic tutorial

I summarized the previous notes on installing MyS...