阅读背景:

Shell进程管理脚本

来源:互联网 
start_process()
{
  p_dir=
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


p_start_cmd= p_name= if [ ! -d $p_dir ]; then echo "process dir is not existed: $p_dir" return 1 fi echo "---- start -- $p_dir: $p_start_cmd" cd $p_dir $p_start_cmd } check_start_process() { p_dir=
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


p_start_cmd= p_name= if [ "$p_name" = "" ]; then echo "process name is not given. " return 1 fi cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l` if [ "$cnt" = "0" ]; then start_process "$p_dir" "$p_start_cmd" "$p_name" else echo "$p_name is running. processes: $cnt" ps -ef|grep -i ${p_name} |grep -v grep fi } wait_process() { p_name=
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


p_time= echo "==== waiting $p_time for $p_name" sleep $p_time pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print }'` while [ "$pid" = "" ] do echo "waiting for $p_name to start" sleep 3 done #echo "==== stop waiting: $p_name is started, pid=$pid" } stop_process() { p_name=
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print }'` if [ "$pid" != "" ]; then echo "kill ${p_name}: $pid" kill -9 $pid else echo "${p_name} is not running." fi } check_process() { p=`ps -ef|grep -i
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


|grep -v grep` if [ "$p" = "" ]; then echo "----
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


is not running!" else echo "$p" fi }start_process() { p_dir=
start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3
  
  if [ ! -d $p_dir ]; then
    echo "process dir is not existed: $p_dir"
    return 1
  fi

  echo "---- start -- $p_dir: $p_start_cmd"
  cd $p_dir  
  $p_start_cmd
}

check_start_process()
{
  p_dir=$1
  p_start_cmd=$2
  p_name=$3

  if [ "$p_name" = "" ]; then
    echo "process name is not given. "
    return 1
  fi
  
  cnt=`ps -ef|grep -i "${p_name}" |grep -v grep|wc -l`
  if [ "$cnt" = "0" ]; then
    start_process "$p_dir" "$p_start_cmd" "$p_name"
  else
    echo "$p_name is running. processes: $cnt"
    ps -ef|grep -i ${p_name} |grep -v grep
  fi
}

wait_process()
{
  p_name=$1
  p_time=$2  

  echo "==== waiting $p_time for $p_name"
  sleep $p_time

  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  while [ "$pid" = "" ]
  do
    echo "waiting for $p_name to start"
    sleep 3
  done
  #echo "==== stop waiting: $p_name is started, pid=$pid"
}

stop_process()
{
  p_name=$1
  pid=`ps -ef|grep -i "${p_name}" |grep -v grep|awk '{print $2}'`
  if [ "$pid" != "" ]; then
    echo "kill ${p_name}: $pid"
    kill -9 $pid
  else
    echo "${p_name} is not running."
  fi
}

check_process()
{
p=`ps -ef|grep -i $1 |grep -v grep`
if [ "$p" = "" ]; then
  echo "---- $1 is not running!"
else
  echo "$p"
fi
}


p_start_cmd=



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: