Use crontab timing tasks to send requests using curl

crontab simple usage

crontab generally comes with the linux system.
Enter the following command to add a scheduled task. There are instructions and examples of crontab in it.

crontab -e

Insert image description here

The sample format is as follows

# 前面五个分别代表分、时、天、月、周,后面就是命令
* * * * * command

For example,
* * * * * commandif it is executed every minute,
5 * * * * commandit is executed at the fifth minute of each hour,
30 6 * * * commandthat is, the command is executed at 6:30 every morning,
and so on.

curl simple usage

Curl is also generally included in the linux system and can be used to send requests
Example requests

curl http://www.baidu.com

By default, a GET request is sent without parameters.

Common parameters

-X 指定请求方式,例如 -X POST
-d 添加请求体的请求参数,增加此参数请求默认变为POST请求,例如 -d "username=sywdebug&password=888888"
-k 跳过ssl验证,如果不加此参数请求https的话会报错
-H 添加请求头,例如 -H {token:sbfjabdoobfda}
-i 获取响应体和响应头
-v 获取响应过程
-I 仅获取响应头

Insert image description here

Topic

Create a new test.sh executable file
Insert image description here

Request the command to be added
Insert image description here

Save and then give execution permission to test.sh
Insert image description here

Use the following command to open the crontab timing task file for editing

crontab -e

Set the execution time and command, execute the test.sh file every minute, and output the response to the test.log file
Insert image description here

After a while, check the files in the folder, and you can see that there is already an additional test.log
Insert image description here

You can see that the requested results have been output.
Insert image description here

Guess you like

Origin blog.csdn.net/sywdebug/article/details/132762988