Hi,
I have got the success in running script using expect module.It is connecting to the remote host but not able to change the password.Please let me know how I can finish this task.Thanks in Advance!!
OUTPUT:
Server1 $ passwd
Changing password for dbaguest
Old password:
+ read line
Main Script:
#!/bin/bash -xv
cat ssh.csv | while read line;
do
username=`echo $line | cut -d, -f1`
addr=`echo $line | cut -d, -f2`
paswd=`echo $line | cut -d, -f3`
echo "$username,$addr,$paswd"
cct=$(./test.exp $paswd $addr $username)
done
Second Script i.e test.exp:
#!/usr/local/bin/expect -f --
set paswd [lindex $argv 0 ]
set addr [lindex $argv 1 ]
set username [lindex $argv 2 ]
spawn ssh $username@$addr
expect {
"> " { }
"$ " { }
"assword: " {
send "$paswd\n"
expect {
"> " { }
"$ " { }
}
}
"(yes/no)? " {
send "yes\n"
expect {
"> " { }
"$ " { }
}
}
default {
send_user "Login failed\n"
exit
}
}
#example command
send "passwd\n"
expect "assword:"
send "$PASSWORD\r"
#"assword: " {
# send "$npaswd\n"
# expect {
# "$ " { }
# }
#}
expect {
"$" {}
default {}
}
#login out
send "exit\n"
expect {
"> " {}
default {}
}
send_user "finished\n"
Regards,
MK