Thursday, June 2, 2011

Script to restart a remote machine, if certain processers found running.

Eg : Usage can be change to any command (eg : shutdon, sending mails, backup ..)


#!/bin/bash
# author SanjeewaF.
# Script will reastrt the remote server if any matching processors found.
# Process 1 : [abc]

if [ ! $1 ] ; then
echo "Please specify the remote IP";
exit
fi
echo "Checking for xyz Processers ========================== ";
ssh root@$1 "if [ `ps -ef | egrep '(\[\babc\b] )' | egrep -v egrep | wc -l` -gt 0 ]; then echo 'xyz processes were found!! System will Restart!!!!'; shutdown -r now; else echo 'xyz processes were Not found...............'; fi"