Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于检查进程是否正在运行的Linux脚本,如果没有,请重新启动_Linux_Bash_Grep_Cron_Pid - Fatal编程技术网

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

用于检查进程是否正在运行的Linux脚本,如果没有,请重新启动,linux,bash,grep,cron,pid,Linux,Bash,Grep,Cron,Pid,我有一个脚本,它查找进程filebeat,如果没有运行,则重新启动它。Cron每5分钟运行一次此脚本。大多数情况下,除了有时会创建多个filebeat进程外,这种方法工作正常。有人能指出我剧本中的问题吗 #!/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

我有一个脚本,它查找进程filebeat,如果没有运行,则重新启动它。Cron每5分钟运行一次此脚本。大多数情况下,除了有时会创建多个filebeat进程外,这种方法工作正常。有人能指出我剧本中的问题吗

#!/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
超级简单:D

超级简单:D

#!/bin/bash
pidof  script.x86 >/dev/null
if [[ $? -ne 0 ]] ; then
        echo "Restarting script:     $(date)" >> /var/log/script.txt
        /etc/script/script.x86 &
fi