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
相关推荐
小白同学_C8 小时前
Lab4-Lab: traps && MIT6.1810操作系统工程【持续更新】 _
linux·c/c++·操作系统os
今天只学一颗糖8 小时前
1、《深入理解计算机系统》--计算机系统介绍
linux·笔记·学习·系统架构
不做无法实现的梦~10 小时前
ros2实现路径规划---nav2部分
linux·stm32·嵌入式硬件·机器人·自动驾驶
默|笙11 小时前
【Linux】fd_重定向本质
linux·运维·服务器
陈苏同学12 小时前
[已解决] Solving environment: failed with repodata from current_repodata.json (python其实已经被AutoDL装好了!)
linux·python·conda
“αβ”12 小时前
网络层协议 -- ICMP协议
linux·服务器·网络·网络协议·icmp·traceroute·ping
未定义.22112 小时前
第2篇:请求实战!覆盖GET/POST/请求头/参数全场景
java·python·http·servlet·自动化·jenkins
不爱学习的老登13 小时前
Windows客户端与Linux服务器配置ssh无密码登录
linux·服务器·windows
小王C语言14 小时前
进程状态和进程优先级
linux·运维·服务器