Computing.Net > Forums > Linux > Unix Script for Telnet

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.

Unix Script for Telnet

Reply to Message Icon

Name: Zia
Date: May 7, 2002 at 07:51:24 Pacific
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: junky_toof
Date: May 7, 2002 at 10:15:21 Pacific
Reply:

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]"
}
}
}


0

Response Number 2
Name: David
Date: July 7, 2002 at 15:43:20 Pacific
Reply:

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


0

Response Number 3
Name: Ignasi
Date: July 9, 2002 at 06:34:41 Pacific
Reply:

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
disconnect

set log [open logfile w] ;# open logfile
expect -re .+ { ;# and record everything to it
puts -nonewline $log $expect_out(buffer)
exp_continue
}


Thanks for coops.



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 Linux Forum Home


Sponsored links

Ads by Google


Results for: Unix Script for Telnet

Script for init www.computing.net/answers/linux/script-for-init/19276.html

perl scripts for filtering mail www.computing.net/answers/linux/perl-scripts-for-filtering-mail/13380.html

UNIX Script help www.computing.net/answers/linux/unix-script-help/7820.html