当前位置:网站首页>教你用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
边栏推荐
- Thinkphp5 manual error reporting
- Explained: A Style-Based Generator Architecture for GANs (StyleGAN)
- [trajectory planning] testing of ruckig Library
- 3 big questions! Redis cache exceptions and handling scheme summary
- 英语常用短语
- logback
- The first techo day Tencent technology open day, 628
- 安装 新版本cmake & swig & tinyspline
- 【CVPR 2021】Intra-Inter Camera Similarity for Unsupervised Person Re-Identification (IICS++)
- 【CVPR 2021】Joint Generative and Contrastive Learning for Unsupervised Person Re-identification
猜你喜欢

install opencv-contrib-dev to use aruco code

jz2440---使用uboot燒錄程序

"One week's data collection" -- combinational logic circuit

"One week's work on digital power" -- encoder and decoder

【轨迹规划】Ruckig库的测试
![[pulsar learning] pulsar Architecture Principle](/img/ec/5ab9aabc2beafd4238dc8055ba6fb2.png)
[pulsar learning] pulsar Architecture Principle

【Sensors 2021】Relation-Based Deep Attention Network with Hybrid Memory for One-Shot Person Re-Id

Merrill Lynch data helps State Grid Hubei "golden eye" accurately identify abnormal power consumption

Badge series 4: use of circle Ci

Spark based distributed parallel processing optimization strategy - Merrill Lynch data
随机推荐
Origin of QPM
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
"One week's data collection" - logic gate
計算領域高質量科技期刊分級目錄
Learning to Generalize Unseen Domains via Memory-based Multi-Source Meta-Learning for Person Re-ID
Click the mask layer to close the pop-up window
Flutter's brain map notes are easy to find and search!
js---获取对象数组中key值相同的数据,得到一个新的数组
Merrill Lynch data technology expert team | building a cloud native product system based on containers
jz2440---使用uboot烧录程序
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(2)详解
How to solve the sample imbalance problem in machine learning?
SQL query duplicate record
欧冠比赛数据集(梅西不哭-离开巴萨也可能再创巅峰)
Common circuit design
3 big questions! Redis cache exceptions and handling scheme summary
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.npm ER
Merrill Lynch data helps State Grid Hubei "golden eye" accurately identify abnormal power consumption
集合对象复制
"One week's study of model electricity" - capacitor, triode, FET