How to check a process is already running of the Bash command line for Linux
if not running the start it
Example:
Shell Script 1:#!/bin/sh
program=xxx #process name
sn=`ps -ef | grep $program | grep -v grep |awk 'print $2'` #get pid
if [ "$sn" = "" ] #if '',then not running
then
nohup /home/oracle/xxx & #running in the background
echo start!
else
echo running
fi
Shell Script 2:#!/bin/sh
ps -ef |grep ./FileServer > /dev/null 2>&1 #write pid to /dev/null
if [ $? -eq 0 ] #0 is running
then
echo logprocess running!
else
nohup /home/oracle/xxx &
echo start!
fi
Shell Script 3:#!/bin/sh
count=`ps -fe |grep "log.out" | grep -v "grep" | wc -l`
if [ $count -lt 1 ]; then
/root/sh/restart.sh
How to check a process is already running of the Bash command line for Linux
No comments:
Post a Comment