当前位置:网站首页>教你用shell脚本检测服务器程序是否在运行
教你用shell脚本检测服务器程序是否在运行
2022-06-26 09:33:00 【坦桑尼亚奥杜威峡谷能人】
shell脚本定时检测python程序是否运行
shell脚本
#!/bin/bash
echo "开始检查运费fright_run程序是否运行..."
cd /opt/gh2/app/goods-freight-py
processID=$(ps -ef | grep freight_run.py | grep -v "grep" | awk "{print $2}")
echo $processID
# 判断$processID为空,此处意思为如果$processID为空,那么重启
if [ -z "$processID" ]
then
# 启动运费fright_run程序
echo "运费fright_run程序未运行, 重新启动中..."
#nohup python3 freight_run.py >/dev/null &
nohup python3 freight_run.py >/store/logs/goods-freight-py/startpy.log &
echo "fright_run程序重启成功..."
# 发送邮件, 最好写绝对路径,否则可能会重启成功但是发邮件失败
#cd /opt/gh2/app/goods-freight-py/common
#python3 send_email.py "fright_run程序重启成功..."
python3 /opt/gh2/app/goods-freight-py/common/send_email.py "fright_run程序重启成功..." "${ipAdress}"
else
echo "fright_run程序正在运行中..."
fi
# ps -ef 展示进程
# | grep your_keywords 按关键字筛选
# | grep -v “grep” 屏蔽grep程序本身的进程
# | awk ‘{print $2}’ 只打印第二列
# process_id=${语句} 将语句执行的返回值赋值给process_id,注意等号前后不能有空
# [ -z "$process_id”] 判断$process_id为空
# [[ -z "$process_id”]] 判断$process_id不为空 , 注意这里前后有两个中括号,Shell的这个语法有点奇怪
# kill -9 $process_id 杀掉变量$process_id指定的进程
linux 上 crontab启动sh:
先把shell脚本放到 /opt/gh2/app/goods-freight-py
方式1:vi /etc/crontab 后进入编辑模式,在下边添加
*/1 * * * * sh /opt/gh2/app/goods-freight-py/shell/check_freight_run.sh >/store/logs/goods-freight-py/freightRun.log 2>&1
方式2:连上服务器后,直接
crontab -e 后进入编辑模式,在下边添加
*/1 * * * * sh /opt/gh2/app/goods-freight-py/shell/check_freight_run.sh >/store/logs/goods-freight-py/freightRun.log 2>&1
查看所有定时任务: crontab -l
查看crontab默认日志:tail -f /var/log/cron
注意事项:
如果是window下编写的shell脚本,复制到linux上运行,会报错
解决办法: vim freight.sh 后,在命令行中 先 :set fileformat=unix ,然后再 :wq
试运行freight.sh: bash freight.sh
边栏推荐
- "One week's work on digital power" -- encoder and decoder
- 我在中山,到哪里开户比较好?在线开户安全么?
- "One week's work on Analog Electronics" - power amplifier
- The first techo day Tencent technology open day, 628
- xsync同步脚本的创建及使用(以Debian10集群为例)
- npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER
- Notes on sports planning on November 22, 2021
- LeetCode 接雨水系列 42.(一维) 407.(二维)
- js---获取对象数组中key值相同的数据,得到一个新的数组
- Yolov5 results Txt visualization
猜你喜欢

thinkphp5手动报错

Construction practice of bank intelligent analysis and decision-making platform

【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort
![[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network](/img/a9/1361df052f0474e5c50b948a92c42a.jpg)
[Journal of Computer Aided Design & computer graphics] overview of research on pedestrian re recognition methods based on generated countermeasure network

How does flutter transfer parameters to the next page when switching pages?

Kubernetes cluster deployment (v1.23.5)

【pulsar学习】pulsar架构原理

Mysql database field query case sensitive setting

2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程

Real time data analysis tool
随机推荐
Flink入门——单词统计
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(1)详细解析教程
2021-11-29 轨迹规划五次多项式
Board end power hardware debugging bug
"One week's work on Analog Electronics" - Basic amplification circuit
LeetCode 接雨水系列 42.(一维) 407.(二维)
Notes on sports planning on November 22, 2021
thinkphp5手动报错
MySQL单表500万条数据增、删、改、查速度测试
LeetCode 剑指 Offer II 091.粉刷房子 - 原地修改
Merrill Lynch data tempoai is new!
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
节流,防抖,new函数,柯里化
QPM suspended window setting information
欧冠比赛数据集(梅西不哭-离开巴萨也可能再创巅峰)
Origin of QPM
The shutter tabbar listener is called twice
正则表达的学习
PHP does not allow images to be uploaded together with data (no longer uploading images before uploading data)
全面解读!Golang中泛型的使用