LoginSignup
13
17

More than 5 years have passed since last update.

ShellScriptでプロセスの存在チェック

Last updated at Posted at 2015-08-20

概要

ps aux | grep プロセス名 | grep -v grep | wc -lを実行すると、プロセスが存在しない時は0、存在する時は0以上の値(プロセス数)が返ります。

例: ssh-agentが存在していない時は、ssh-agentを起動してssh鍵を登録するShellScript

# ~/.bash_profile

# githubの鍵を登録する
count=`ssh-add -L | grep github_office_rsa | grep -v grep | wc -l`
if [ $count = 0 ]; then
  killall ssh-agent
  eval "$(ssh-agent -s)"
  ssh-add ~/.ssh/github_office_rsa
fi
13
17
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
17