Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 pizzaspawn 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 \nset timeout 5
exp_continue
}
}
}
}catch { interact }
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Appreciate your advice,
Nish.

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...

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

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