1826325 Members
3510 Online
109692 Solutions
New Discussion

Monitoring if ssh works

 
SOLVED
Go to solution
Rohit Khaladkar
Occasional Contributor

Monitoring if ssh works

Hi All,
I have a setup of around 100 servers with atleast 10 users on each box.The public key from one server has been created and updated on all other servers , so that passwordless login can be done from any use.


We recently had a problem that ssh keys on one of the system was changed and scripts using ssh failed.

I want to come up with a bash script to check if ssh is successful from one server to all servers using all users (All permutations and combinations)

Any ideas would be appreciated.
5 REPLIES 5
F Verschuren
Esteemed Contributor

Re: Monitoring if ssh works

does the users have a passprase?
if not, just su to the user and ssh to all serverslike

cat /tmp/list
server1
server2
serveretc
=======
su - user
cat /tmp/list|while read line
do
ssh $line uname -a
done >> /tmp/file
and check the /tmp/file
Rohit Khaladkar
Occasional Contributor

Re: Monitoring if ssh works

This is something I cam up with:

Host_name_list="path of the file which has hostnames"
User_name_list="path of the file which has usernames"
Log_file="path to the file which would contain all the ssh log entries"

for host_name in $Host_name_list
do
for user in $User_name_list
do
ssh -q -o "BatchMode=yes" ${user}@${host} "echo 2>&1" && echo "Successful for" $user@$host_name\
|| echo "Failed for" $user@$host_name"

done
done

mailx -s "This is it" rohit.khaladkar@xyz.com < $Log_file


Is there a better way out..?
Bill Hassell
Honored Contributor
Solution

Re: Monitoring if ssh works

> ssh -q -o "BatchMode=yes" ...

I would probably add -n to handle stdin since there won't be any stdin.


Bill Hassell, sysadmin
Emil Velez
Honored Contributor

Re: Monitoring if ssh works

why not use aide or tripwire cron jobs on each system to detect when something changed on the systems.
Steven Schweda
Honored Contributor

Re: Monitoring if ssh works

> why not use aide or tripwire cron jobs on
> each system to detect when something
> changed on the systems.

Sometimes it's useful to test the actual
thing which you care about. It may be
possible to use X-rays or neutrons or
ultrasonic sound or eddy currents, or any
number of other methods, to test a hammer,
but it's often easier and more reliable just
to hit a nail with the thing, and see what
happens. There are advantages to "simple and
direct".