14
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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
14
18
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
14
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?