linux bash shell http请求脚本

/opt/refreshCache/refreshCache.sh

复制代码
[umed@VM-0-14-centos logspayment]$ more /bin/bash /home/umed/opt/refreshCache/refreshCache.sh

******** /bin/bash: Not a text file ********

::::::::::::::
/home/umed/opt/refreshCache/refreshCache.sh
::::::::::::::
#!/bin/bash

# 定义接口地址
URL1="https://hlwyy.yy.com/rbu/open/uipHttp/refresh?hospitalId=&uhospitalId=81d6ee37-afc3-4625-8720-ee916a6ebeb1"
URL2="https://hlwyy.yy.com/ibh/consultapi//config/hospitalConfig/updateConfig?unionId=33&hospitalId=1120010613414232310"

# 定义日志文件路径,下方的 /path/to/your/logfile.log 需要改成自己项目上的路径,切记!
LOG_FILE="/home/umed/opt/refreshCache/logfile.log"

# 定义函数,用 curl 发送请求,并打日志
function send_request {
    URL=$1
    echo "Sending GET request to $URL" >> $LOG_FILE
    RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" $URL)
    if [ $RESPONSE -eq 200 ]; then
        echo "Successfully refreshed $URL at $(date)" >> $LOG_FILE
    else
        echo "Failed to refresh $URL at $(date). HTTP response code: $RESPONSE" >> $LOG_FILE
    fi
}

# Send GET requests
send_request $URL1
send_request $URL2

定时任务crontab

复制代码
[umed@VM-0-14-centos logspayment]$ sudo crontab -u root -l
*/5 * * * * flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &'
0 0 * * * /bin/bash /home/umed/opt/refreshCache/refreshCache.sh
相关推荐
影龙帝皖7 分钟前
Linux服务之lvs+keepalived nginx+keepalived负载均衡实例解析
linux·nginx·lvs
八月的雨季 最後的冰吻16 分钟前
SIP协议栈--osip源码梳理
linux·服务器·网络·c++·网络协议
敖云岚1 小时前
【Linux】基于虚拟机实现网络的管理
linux·服务器·网络
luck_me51 小时前
如何远程执行脚本不留痕迹
linux·运维·服务器
-SGlow-1 小时前
Linux相关概念和易错知识点(40)(HTML资源交互、网页管理、搜索引擎)
linux·运维·服务器·网络·html·交互
默心2 小时前
centos7部署mysql5.7
linux·运维·mysql·centos
-SGlow-2 小时前
Linux相关概念和易错知识点(39)(URL、HTTP)
linux·运维·http
因缘而起12 小时前
【Linux】gcc从源码编译安装,修改源码,验证修改的源码
linux·运维·服务器
山川而川-R3 小时前
开机自启动python程序_ubuntu22.04
linux·运维·服务器
巴巴_羊4 小时前
AJAX 使用 和 HTTP
前端·http·ajax