简体   繁体   English

Linux脚本,用于检查进程是否正在运行,如果没有,则重新启动

[英]Linux Script to check if process is running and restart if not

I am having this script which looks for the process filebeat and restarts it if is not running. 我正在使用此脚本查找进程文件 ,如果未运行,请重新启动它。 Cron runs this script every 5 minutes. Cron每5分钟运行一次此脚本。 Most of the time this works fine except sometime it creates multiple filebeat process. 在大多数情况下,此方法工作正常,但有时会创建多个filebeat进程。 Can someone please point out what is the issue in my script. 有人可以指出我脚本中的问题是什么。

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
service=filebeat
servicex=/usr/share/filebeat/bin/filebeat
pid=`pgrep -x "filebeat"`
if [ $pid > /dev/null ]
then
echo "$(date) $service is running!!!"
else
echo "$(date) starting $service"
cd /home/hpov/beats/filebeat
./filebeat -c filebeat.yml &
fi
#!/bin/bash
pidof  script.x86 >/dev/null
if [[ $? -ne 0 ]] ; then
        echo "Restarting script:     $(date)" >> /var/log/script.txt
        /etc/script/script.x86 &
fi

Super easy :D 超级容易:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM