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
相关推荐
是店小二呀1 天前
仓颉三方库开发实战:Simple HTTP Server 实现详解
网络·网络协议·http
Lolo_fi1 天前
记录Fedora43上安装向日葵
linux
noravinsc1 天前
两台 centos 7.9 部署 pbs version 18.1.4 集群
linux·运维·centos
你的微笑,乱了夏天1 天前
linux centos常用命令整理
linux·运维·centos
故林丶1 天前
【Linux】CentOS 7.8 Docker + Docker Compose 安装
linux·docker·centos
刘一说1 天前
CentOS系统一键安装Memcached教程
linux·centos·memcached
不惑_1 天前
[特殊字符] 在 Linux 上设置 SQLite
linux·jvm·sqlite
淮北4941 天前
如何在ubuntu调用exe文件
linux·运维·ubuntu
HalvmånEver1 天前
Linux:基础开发工具(一)
linux·运维·服务器·开发语言·学习·进阶学习
HIT_Weston1 天前
26、【Ubuntu】【远程开发】内网穿透:密钥算法介绍(二)
linux·运维·ubuntu