Saturday, February 11, 2012

Pgrep

Here's a one liner that gets a pid off a remote host and returns it to Nagios. This one took a little effort. Running pgrep across ssh returns two pids, the target pid and the pid of the pgrep search. These were undesireable results because I didn't want the pgrep pid. To simulate grep's -v switch I chose to use brackets, [ ]. This worked perfectly. Here's the code-

ssh -p 4231 user@10.98.34.199 'if ! pgrep -f '/[h]ome/user/diamonds.cfg.server'; then echo 'Diamond not running!'; exit 1; fi'

No comments: