惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
月光博客
月光博客
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
小众软件
小众软件
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
罗磊的独立博客
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 三生石上(FineUI控件)
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
博客园 - 聂微东
V
V2EX

Allen Hua 的网络博客

由于 Linux 桌面没有一个好用的天气程序就写了一个跨平台的CheckitoutWeather 给 caesium-image-compressor 图片压缩程序构建了 Linux AppImage v2.8.5 最新版 debian13(debian trixie)安装了nvidia闭源驱动后从x11切换到wayland的方法 山间摩旅追风,偶遇一场绚烂晚霞 最近使用debian系统的一些心得 机械革命无界14Pro笔记本debian forky成功驱动内置扬声器和麦克风 记录 typecho 1.2.0 升级到 1.3.0 过程 开发了一款openwrt插件:文本剪贴板 解决机械革命笔记本内屏高刷240Hz闪屏问题 使用 Java 写了一个局域网端口扫描器 - Allen Hua 的网络博客 openwrt使用外置根extroot机制扩展根分区大小 - Allen Hua 的网络博客 将机场ss节点批量转换成ss字符串链接批量添加到passwall - Allen Hua 的网络博客 给机械革命钛钽plus换屏:NY2换成NZ2 - Allen Hua 的网络博客 记录一次pve宿主机和上面的debian虚机无故down机事件 - Allen Hua 的网络博客 给图床部署cdn腾讯云的edgeone并排查Cache-Control max-age 3600的问题 - Allen Hua 的网络博客 从高山草甸到徽派古村:武功山反穿与皖浙赣自驾行记 - Allen Hua 的网络博客 增程器就是充电宝?别被忽悠了 - Allen Hua 的网络博客 浦口龙虎巷扫街,记录人间真实 博客图片压缩方案更新|AVIF|WebP|MozJPEG|标准JPEG Windows 电脑使用 Obs Studio 录制各个网站视频/桌面画面教程 为typecho博客添加latex支持 新能源汽车之纯电车使用交流慢充和直流快充的充电损耗对比 2025年3月更新全国5A景区名录 2025最新查看小米/红米手机电池健康度和循环次数方法 完美解决 seafile FILE_SERVER_ROOT 配置导致的内网外网不能同时访问和上传下载的问题 纯css实现typecho博客文章文字spoiler剧透效果 我对Typecho Facile主题的一些修改,图片懒加载优化,样式定制 2024年8月我的宜昌 - 重庆 - 川西小环线自驾旅行分享 2022年打卡南京市区人防工程纳凉点 2024年带着A7C2+腾龙28-200 再次来到红山森林动物园
写shell脚本监测vps上的frps进程是否存在,不存在自动重启
Allen Hua · 2021-06-07 · via Allen Hua 的网络博客
阅读量:3574

warning: 这篇文章距离上次修改已过1814天,其中的内容可能已经有所变动。

写下面文本到文件 /home/sftp/check_frps.sh

#!/bin/bash

# author: hellodk

# time: 2021-05-28 16:14:26

# script feature description: check if frps is running, if not, start it

function check_frps(){

  time3=$(date "+%Y-%m-%d %H:%M:%S")

  frpsCount=`ps aux | grep "/usr/local/frp/frps -c /usr/local/frp/frps.ini" |grep -v grep |wc -l`

  if [ 0 == $frpsCount ]; then

      echo $time3 "current running frps process count: "$frpsCount ", meaning frps daemon is dead, now start it" >> /home/sftp/check_frps.log
      nohup /usr/bin/systemctl start frp >> /home/sftp/check_frps.log 2>&1 &
   else
      echo $time3 "current running frps process count: "$frpsCount ", and no need to start frps" >> /home/sftp/check_frps.log

  fi

}

check_frps

脚本是没有问题的,使用bash执行也是正常,日志打印也正常,但就是在我的那台硬件配置比较差的vps上总是无法使用 crontab 保存执行

每次使用 crontab -e 新增一行然后保存退出,成功提示crontab: installing new crontab 但是过了一段时间后发现这行就不见了……

脚本自然也就没有按照预期执行。

由于这一台主机挂了京东薅羊毛的脚本,后续发现了问题所在。

在狗东薅羊毛控制面板(web端)直接编辑了这个cron list,成功新增一行,web的提示是成功修改了 crontab.list 文件,后面通过 find 命令找到了

# find / -name crontab.list
/opt/jd/config/crontab.list

我应该直接修改这个文件,新增我的cron计划。

需要额外重点关注:crontab -e 命令编辑的文件是 /var/spool/cron 目录下的具体的用户名文件 比如 root, 具体文件是 /var/spool/cron/root

0 0-23/1 * * * bash /home/sftp/check_frps.sh, 含义是每隔一小时执行一次这个 shell 脚本 或者 0 */1 * * * bash /home/sftp/check_frps.sh 这两个命令都代表每隔一小时执行一次(也就是每小时检查一次frps进程是否存在)

将这行新增到 /opt/jd/config/crontab.list 文件末尾保存退出即可。后续查看脚本发现稳定运行~

看看日志

# tail -n 15 /home/sftp/check_frps.log
2021-06-06 20:00:01 current running frps process count: 1 , and no need to start frps
2021-06-06 21:00:02 current running frps process count: 1 , and no need to start frps
2021-06-06 22:00:01 current running frps process count: 1 , and no need to start frps
2021-06-06 23:00:01 current running frps process count: 1 , and no need to start frps
2021-06-07 00:00:04 current running frps process count: 1 , and no need to start frps
2021-06-07 01:00:02 current running frps process count: 0 , meaning frps daemon is dead, now start it
2021-06-07 02:00:02 current running frps process count: 1 , and no need to start frps
2021-06-07 03:00:02 current running frps process count: 1 , and no need to start frps
2021-06-07 04:00:02 current running frps process count: 1 , and no need to start frps
2021-06-07 05:00:01 current running frps process count: 1 , and no need to start frps
2021-06-07 06:00:01 current running frps process count: 1 , and no need to start frps
2021-06-07 07:00:02 current running frps process count: 1 , and no need to start frps
2021-06-07 08:00:02 current running frps process count: 1 , and no need to start frps
2021-06-07 09:00:01 current running frps process count: 1 , and no need to start frps
2021-06-07 10:00:02 current running frps process count: 1 , and no need to start frps

问题解决了。end.