Then create this script and use it..
run this as your user (ID) which should have sudo access.
#!/usr/bin/expect -f
set ip_file "/export/home/userid/devsrvlist"
set fid [open $ip_file r]
while {[gets $fid ip] != -1} {
spawn ssh $ip
expect "Password:"
send "password\r"
expect "~$"
send "uname -n\r"
send "sudo passwd userid\r"
expect "Password:"
send "Password\r"
expect "New Password:"
send "newpasswd\r"
expect "Password:"
send "newpasswd\r"
expect "~$"
send "sudo passwd -f userid\r"
send "exit\r"
expect eof
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++
https://likegeeks.com/expect-
questions - is a bash script - spawn will run a script or command
#!/usr/bin/expect -f
set my_name [lindex $argv 0]
set my_favorite [lindex $argv 1]
set timeout -1
spawn ./questions
expect "Hello, who are you?\r"
send -- "Im $my_name\r"
expect "Can I ask you some questions?\r"
send -- "Sure\r"
expect "What is your favorite topic?\r"
send -- "$my_favorite\r"
expect eof
$ ./answerbot SomeName Programming
SomeName will be replaced for $my_name = lindex $argv 0
No comments:
Post a Comment