shell programming: the use of scripts to achieve automatic restart nginx guardian

nginx_daemon.sh

#!/bin/bash
#

this_pid=$$

while true
do
ps -ef | grep nginx | grep -v grep | grep -v $this_pid &> /dev/null

if [ $? -eq 0 ];then
          echo "nginx is ok"
          sleep 3
else
          systemctl start nginx
          echo "nginx is down,starting it..."
fi
done

Execute scripts

The background script and output log to the / tmp / nginx_daemon.out 

SH nginx_daemon. SH > /tmp/nginx_daemon.out 2 > & 1 & 

( SH nginx_daemon. SH &    do not specify a file, then for the files in the current directory nohup.out) 

View log 

tail -f /tmp/nginx_daemon.out

View tasks

View tasks. 

jobs 

Close Task 

fg % the n- 

 

Guess you like

Origin www.cnblogs.com/soymilk2019/p/11723708.html