当前位置:网站首页>Teach you to use shell script to check whether the server program is running
Teach you to use shell script to check whether the server program is running
2022-06-26 09:43:00 【Tanzanian auduvi Canyon expert】
shell Script timing detection python Whether the program is running
shell Script
#!/bin/bash
echo " Start checking the freight fright_run Whether the program is running ..."
cd /opt/gh2/app/goods-freight-py
processID=$(ps -ef | grep freight_run.py | grep -v "grep" | awk "{print $2}")
echo $processID
# Judge $processID It's empty , This means if $processID It's empty , So restart
if [ -z "$processID" ]
then
# Start freight fright_run Program
echo " The freight fright_run The program is not running , Restarting ..."
#nohup python3 freight_run.py >/dev/null &
nohup python3 freight_run.py >/store/logs/goods-freight-py/startpy.log &
echo "fright_run Program restart succeeded ..."
# Send E-mail , It's better to write absolute path , E-mail restart may fail
#cd /opt/gh2/app/goods-freight-py/common
#python3 send_email.py "fright_run Program restart succeeded ..."
python3 /opt/gh2/app/goods-freight-py/common/send_email.py "fright_run Program restart succeeded ..." "${ipAdress}"
else
echo "fright_run The program is running ..."
fi
# ps -ef Show progress
# | grep your_keywords Filter by keyword
# | grep -v “grep” shielding grep The process of the program itself
# | awk ‘{print $2}’ Print only the second column
# process_id=${ sentence } Assign the return value of the statement execution to process_id, Note that you can't be free before and after the equal sign
# [ -z "$process_id”] Judge $process_id It's empty
# [[ -z "$process_id”]] Judge $process_id Not empty , Notice that there are two brackets before and after ,Shell The grammar of is a little strange
# kill -9 $process_id Kill variables $process_id Specified process
linux On crontab start-up sh:
The first shell Put the script in /opt/gh2/app/goods-freight-py
The way 1:vi /etc/crontab Enter editing mode after , Add below
*/1 * * * * sh /opt/gh2/app/goods-freight-py/shell/check_freight_run.sh >/store/logs/goods-freight-py/freightRun.log 2>&1
The way 2: After connecting to the server , direct
crontab -e Enter editing mode after , Add below
*/1 * * * * sh /opt/gh2/app/goods-freight-py/shell/check_freight_run.sh >/store/logs/goods-freight-py/freightRun.log 2>&1
View all scheduled tasks : crontab -l
see crontab The default log :tail -f /var/log/cron
matters needing attention :
If it is window Written in the second part shell Script , Copied to the linux Up operation , Will report a mistake
terms of settlement : vim freight.sh after , On the command line First :set fileformat=unix , And then again :wq
A test run freight.sh: bash freight.sh
边栏推荐
- 0 basic how to make a cool leadership cockpit?
- 力扣------从数组中移除最大值和最小值
- js---获取对象数组中key值相同的数据,得到一个新的数组
- 我在中山,到哪里开户比较好?在线开户安全么?
- 【轨迹规划】Ruckig库的测试
- 点击遮罩层关闭弹窗
- 我的创作纪念日
- Master data management of scientific research institutes? Suppliers or customers? I am a correspondent
- How to solve the sample imbalance problem in machine learning?
- 2021-11-12 vrep vision sensor configuration
猜你喜欢
Record a time when the server was taken to mine
【AAAI 2021】Few-Shot One-Class Classification via Meta-Learning 【FSOCC via Meta-learning】
2021-11-29 quintic polynomial of trajectory planning
深度学习(初识tensorflow2.版本)之三好学生成绩问题(1)
Champions League data set (Messi doesn't cry - leaving Barcelona may reach another peak)
How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card
The most complete and simple nanny tutorial: deep learning environment configuration anaconda+pychart+cuda+cudnn+tensorflow+pytorch
2021-11-22 运动规划杂记
"One week's work on Analog Electronics" - integrated operational amplifier
The first techo day Tencent technology open day, 628
随机推荐
js---获取对象数组中key值相同的数据,得到一个新的数组
Redis 新手入门
install realsense2: The following packages have unmet dependencies: libgtk-3-dev
Throttling, anti chattering, new function, coriolism
2021年全国职业院校技能大赛(中职组)网络安全竞赛试题(2)详解
Flutter's brain map notes are easy to find and search!
QPM suspended window setting information
SQL高级教程
How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card
CVPR:Refining Pseudo Labels with Clustering Consensus over Generations for Unsupervised Object Re-ID
Collection object replication
Jz2440 - - - utiliser le programme de gravure uboot
安装 新版本cmake & swig & tinyspline
Industrial and enterprise patent matching data (hundreds of thousands of data) 1998-2014
How to create an IE tab in edge browser
Regular expression learning
pcl install
Abnormal record-23
install opencv-contrib-dev to use aruco code
Comparison of similar PMS in QPM