Computing.Net > Forums > Unix > Telnet using expect script

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.

Telnet using expect script

Reply to Message Icon

Name: Nish
Date: June 25, 2003 at 00:59:58 Pacific
OS: Solaris
CPU/Ram: 512
Comment:

Hi All,

I need to hardcore my username and password in a script and loginto the server reotely. Then I need to log as su and send init 5 message to shutdown the server.
I tried with following script, but it fails to login in to the machine.

#!/usr/local/bin/expect --
set username hello
set password pizza

spawn telnet 192.168.100.20

expect {
-re "\[L|l\]ogin:" {
exp_send username\n
exp_send password\n
if { $mode != "PasswordSent" } {
set timeout 1
set mode SendLogin
exp_continue
}
}
-re ".*Password:" {
set timeout 1
set mode SendPassword
exp_continue
}
}
timeout {
switch $mode {

SendLogin {
send $username
send \n
exp_continue
}
SendPassword {
send $password
send \n

set timeout 5
exp_continue
}
}
}
}

catch { interact }

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Appreciate your advice,

Nish.



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: June 25, 2003 at 04:41:03 Pacific
Reply:

Instead of spawning a telnet process, spawn a shell and send the rest of the commands.

spawn "/bin/sh"
send "telnet $HOSTNAME\r"
sleep 1
expect "ogin"
send "$username\r"
expect "Password"
send "$password\r"
send "\r\r"

etc...


0

Response Number 2
Name: James
Date: July 14, 2003 at 21:51:00 Pacific
Reply:

How can the same thing be done from a windows system into unix?

Thanks in advance.


0

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: Telnet using expect script

Automate telnet using Expect www.computing.net/answers/unix/automate-telnet-using-expect/4441.html

Expect script to su and run passwd www.computing.net/answers/unix/expect-script-to-su-and-run-passwd/6154.html

how to execute a expect script www.computing.net/answers/unix/how-to-execute-a-expect-script/5382.html