bash+crontab充当半个守护进程的歪招

两个cpolar下的不同程序,都需要定时监测,以免程序没有再运行。有点类似半个守护进程吧。但是守护进程不会写,咋搞?就用这个办法临时当下守门员。这里主要为了备忘xpgrep -各类参数的用法。

bash 复制代码
#!/bin/bash

if pgrep -fl "check_cpolar.sh" > /dev/null #check_cpolar是另一个更主要的程序,必须确保它跑着,再跑这个次要监控程序。
then
    #把命令结果赋值给变量,var1要是等于var2说明次要的这个程序没跑起来。
    var1=$(pgrep -x -o "cpolar")
    var2=$(pgrep -x -n "cpolar")
    if [ $var1 = $var2 ];
    then
	#启动次要程序。
    fi
fi
相关推荐
IMPYLH42 分钟前
Linux 的 b2sum 命令
linux·运维·服务器·bash
波特率11520012 小时前
bash命令进阶学习(Shell 元字符)
linux·bash·shell
knighthood20011 天前
ROS1中source xxx.bash失效
开发语言·bash
IMPYLH1 天前
Bash 的 basenc 命令
linux·运维·服务器·bash·shell
IMPYLH1 天前
Linux 的 arch 命令
linux·运维·服务器·bash
Be for thing2 天前
Bash 编程语法
学习·bash
IMPYLH2 天前
Linux 的 base64 命令
linux·运维·服务器·bash·shell
IMPYLH2 天前
Linux 的 base32 命令
linux·运维·服务器·bash·shell
LuL_Vegetable2 天前
写一个Linux服务器自动tcpdum抓包脚本
linux·wireshark·bash·tcpdump
勿芮介4 天前
【研发工具】OpenClaw基础环境安装全教程-Node\NVM\PNPM\Bash
开发语言·node.js·bash·ai编程