Hi All,
I need to run the same command on many servers. I am using ssh for the same. Following is the script that I am using to fire the same command on multiple machines.
#!/bin/bash
# Linux/UNIX box with ssh key based login
#SERVERS="iqmevrick,iqmango"
# SSH User name
USR="root"
# connect each host and pull up user listing
for host in `cat list`
do
ssh $USR@$host date
done
But the problem is I need to have this script running without asking password.So it has to be non-interactive. I tried using expect script for the same. Following is the expect script that I came up with, but it is not working.
Can someone please help...
#!/usr/bin/expect -f
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh root@$ipaddr date
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof