Shell script implements scheduled notification of DingTalk robot

1. First, you can use the following command to see whether your server has many scheduled tasks. If an error is reported, you need to install crontab. (Check how to install it yourself)

crontab -l 

2. Find a directory and create a .sh file. 

vi send_msg.sh

3. Copy the following code (replace the last address with your own WEBHOOK)

curl -X POST  -H 'Content-Type: application/json' -d '  {"msgtype": "text",  "text": { "content": "周末了,早点下班哟" } }' https://oapi.dingtalk.com/robot/send?access_token=b5c

4. Can you execute it to see if it works?

./send_msg.sh

5. If it is easy to use, you need to create a scheduled task class and execute the following command

crontab -e   

6. Modify and add your own scheduled tasks (crontab expression: representing minutes, hours, days, months, and weeks in sequence)

0 18 * * 5 sh /opt/dingding/send_msg.sh >> /opt/dingding/test.txt

 

Guess you like

Origin blog.csdn.net/bfy0914/article/details/102747227