Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a requirment to fetch IP, username, password form a file(suppose details.txt) and ssh to those IP one by one and then run some commands on them.This has to be done using expect.
Can anyone tell me how can we fetch IP,Username,Password and use them in expect script.Below are the files which i am using
--------Details.txt
============192.182.53.45,aks,aks
192.183.55.82,aks,aks
expect Script
=============
#!/usr/local/bin/expect -f#set remote_serverfile "~/provisoip"
set fp [open "~pvuser/details.txt" "r"]
set remote_server ukdmo1
set my_user_id pvuser
set my_password pvuser
set cmdfile1 "commandtel"#echo "$remote_server"
set line 0
while {[gets $fp buf]='\n'}{
#spawn telnet $remote_server
spawn telnet $fp
expect "login:"
# Send the username, and then wait for a password prompt.expect "login:"
# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "Password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"
expect "$"
# Send the prebuilt command, and then wait for another shell prompt.send "$cmdfile\r"
send "exit\r"
expect eof
}
incr lineRegards,
Alpana

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |