sh Bash - 检查流程示例 - 来自http://stackoverflow.com/questions/7708715/check-if-program-is-running-with-ba

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Bash - 检查流程示例 - 来自http://stackoverflow.com/questions/7708715/check-if-program-is-running-with-ba相关的知识,希望对你有一定的参考价值。

#!/bin/bash

check_process() {
  echo "$ts: checking $1"
  [ "$1" = "" ]  && return 0
  [ `pgrep -n $1` ] && return 1 || return 0
}

while [ 1 ]; do 
  # timestamp
  ts=`date +%T`

  echo "$ts: begin checking..."
  check_process "dropbox"
  [ $? -eq 0 ] && echo "$ts: not running, restarting..." && `dropbox start -i > /dev/null`
  sleep 5
done

以上是关于sh Bash - 检查流程示例 - 来自http://stackoverflow.com/questions/7708715/check-if-program-is-running-with-ba的主要内容,如果未能解决你的问题,请参考以下文章

sh Bash If语句示例 - 来自http://www.thegeekstuff.com/2010/06/bash-if-statement-examples

sh Bash - 时间戳功能示例 - 来自http://stackoverflow.com/questions/17066250/create-timestamp-variable-in-bash

sh Bash - 时间戳功能示例 - 来自http://stackoverflow.com/questions/17066250/create-timestamp-variable-in-bash

sh 来自终端的快速提醒(bash)

sh 监视RSS提要以获取来自bash的更改

sh Bash:检查用户是否为root