0

How do I go about checking that a certain process is running in another box and return a value? For example, if I wanted to check that process 'FTP' is running in 192.168.1.1 from box 192.168.1.2, how would I return a success flag? I would like to incorporate a script that would check a certain process is running within a cluster of servers.

I tried to come up with something without much success:

for i in 'cat server_list.txt';
     do ssh $i
          "ps -ef | grep ftp = process;
          if [ $process -eq 1]
              then 
                  echo "ftp process is running"
          fi"

I would like to have a return letting me know that the 'ftp' process is running. There are a list of servers IP in the server list text file.

1
while read -r host; do
   if ssh -n "$host" "pgrep '^ftp$'"; then
      echo "A process named 'ftp' is running on ${host}."
   fi
done < /path/to/server_list
  • This doesn't seem to return anything even if the process is running – keyboard_solo Oct 18 '16 at 16:15
  • Wouldn't that ssh consume all input on standard in, thus emptying the list of hosts past the first? – thrig Oct 18 '16 at 16:22
  • @thrig you are right, I fixed my edit – jordanm Oct 18 '16 at 16:48
  • @keyboard_solo the answer this provides only matches exactly "ftp". You may want to remove the ^$ anchors and/or add -f to pgrep. – jordanm Oct 18 '16 at 16:49
  • I put those in so as to match the exact process name specified in the question. Otherwise, it would false-positive on e. g. ftpd. – DopeGhoti Oct 18 '16 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.