Computing.Net > Forums > Unix > Expect usage in Unix

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Expect usage in Unix

Reply to Message Icon

Name: alpana
Date: March 1, 2006 at 05:07:45 Pacific
OS: Solaris
CPU/Ram: no idea
Product: no idea
Comment:

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 line

Regards,
Alpana



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Expect usage in Unix

Highlighting words in unix www.computing.net/answers/unix/highlighting-words-in-unix/4592.html

Deleting a file in unix www.computing.net/answers/unix/deleting-a-file-in-unix-/7581.html

Need drivers for DFE-530TX in UNIX! www.computing.net/answers/unix/need-drivers-for-dfe530tx-in-unix/2251.html