Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
HI Gurus
I need Unix Shell Script for Telnet , Can any one help me if he has already. I saw some old posts here for same problem , but not solutions in it. Looking fwd for help soon .
Thanks for all
BRs
zia

Use EXPECT.
http://expect.nist.gov
#!/pathtoexpect
#globals
exp_internal 0
set timeout 125
log_user 0
set prompt "myname@hostname"
proc get_str {str} {
puts -nonewline $str stdout
flush stdout
stty -echo
set rr [gets stdin]
stty echo
return $rr
}
catch {
spawn -noecho telnet [lindex $argv 0]
set id $spawn_id
expect {
-re ".*ogi.*" {
set l [get_str "Need login: "]
send "$l\r"
exp_continue
}
-re ".*asswor.*" {
set l [get_str "Need Password: "]
send "$l\r"
exp_continue
}
-re "$prompt" {
send_user "Logged in\n\n"
interact {}
}
eof {
send_user "Caught premature eof."
close ; wait
}
timeout {
send_user "Timed out on [lindex
$argv 0]"
}
}
}

Hi Gurus,
Is there any version of such code which save everything to a file after a telnet is send?.
I'd like to send "telnet " and then send a command to a remote console which does not request for user and password. After it i'd like to see the answer into a file.
Thanks for coops.
Brgds, David

Hi,
I'd like to end a telnet process but without waiting for a ^Z as described below according to an "expect" example.
If I remote ^Z, the file is empty. Is there any other way to stop the process without waiting for the user action.
The unix action is
$expect telnet.sh > file.dat
The telnet.sh code is:
spawn -ignore HUP telnet $IP $PORT;# start telnet
interact \032 return ;# interact until ^Z
if {[fork]} exit ;# disconnect from terminal
disconnectset log [open logfile w] ;# open logfile
expect -re .+ { ;# and record everything to it
puts -nonewline $log $expect_out(buffer)
exp_continue
}
Thanks for coops.

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

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