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 script
Background Execute the script and output the log to /tmp/nginx_daemon.out
sh nginx_daemon.sh> /tmp/nginx_daemon. out 2>&1 &
(sh nginx_daemon.sh & If you do not specify a file, it is in the nohup.out file of the current directory)
View log
tail -f /tmp/nginx_daemon.out
View task
View tasks.
jobs
Close task
fg %n
#!/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 the script in the background and output the log to /tmp/nginx_daemon.out
sh nginx_daemon.sh> /tmp/nginx_daemon. out 2>&1 &
(sh nginx_daemon.sh & If you do not specify a file, it is in the nohup.out file of the current directory)
View log
tail -f /tmp/nginx_daemon.out
View tasks.
jobs
Close task
fg %n