公司的点晚饭时间是11点半到下午3点。忙起来真的很容易忘记,今天话不多说,直接开搞一个机器人提醒我们点饭
。本教程基于centos7版本
#!/bin/sh
. /etc/profile
. ~/.bash_profile
curl 'https://oapi.dingtalk.com/robot/send?access_token=da69d946905ba69e57d548257461223f2d4b7d9dc1fd0393939e656c' \
-H 'Content-Type: application/json' \
-d '{
"at": {
"atMobiles":[
"phone1"
],
"atUserIds":[
],
"isAtAll": true
},
"text": {
"content":"[备忘]到点了,快,点饭点饭,点饭点饭"
},
"msgtype":"text"
}'
注意事项:
至此推送内容的脚本已经完成了。我的最终脚本代码如下,前两行是加载环境的,稳妥起见可以加,也可以不加。
#!/bin/sh
. /etc/profile
. ~/.bash_profile
curl 'https://oapi.dingtalk.com/robot/send?access_token=67cbf6b18dbf6f22e6d4765a34XXXXXXXX39788aa18a93aa2ca01e4239' \
-H 'Content-Type: application/json' \
-d '{
"at": {
"atMobiles":[
],
"atUserIds":[
],
"isAtAll": true
},
"text": {
"content":"[备忘]到点了,快,点饭点饭,点饭点饭"
},
"msgtype":"text"
}'
然后我们执行脚本测试一下是否能推送过去 。输入bash jiaoben.sh 很棒已经成功了
接下来我们要设置定时任务,让系统自动推送
我想让我的脚本在11-13点之间,每隔半小时一次,提醒我点餐。接下来输入crontab -e 。我们进行新增一个定时任务内容如下。完事后 :wq 保存并退出
0,30 11-13 * * * bash /hustudy/remindhuandwang.sh
新建定时任务之后,我们重启定时任务服务。就OK了
重启命令:systemctl restart crond.service
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有