Computing.Net > Forums > Unix > Can anyone help with telnet 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.

Can anyone help with telnet script

Reply to Message Icon

Name: Chris L
Date: October 11, 2002 at 01:45:34 Pacific
OS: HP-UX 11
CPU/Ram: 768 MB
Comment:

I am assured this script runs on a Sun box using a bash shell, but I can’t get it to run on a HP-UX box. It’s intended to sequentially telnet each IP address in a file, get a prompt, run a command, and log the response. On the Sun box each of the telnet sessions automatically close, but on the HP-UX box the first telnet session stays up, and the script hangs.

The remote machines won't accept unix commands, so I can’t use rlogin or remsh. Any ideas or suggestions?

for IP in `cat IP_list.dat`
do
(echo "";\
echo "MyCommand";\
echo "exit;";\
sleep 5)|telnet $IP >> MyResult
done

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: October 11, 2002 at 03:01:54 Pacific
Reply:

Bash or ksh does not lend themselves to interactive telnet sort of scripts. Have a look at expect.


0

Response Number 2
Name: jimbo
Date: October 11, 2002 at 03:07:29 Pacific
Reply:

I'd look into using expect or perl to do this. Here is a link to the perl module i use for this task:

http://search.cpan.org/author/JROGERS/Net-Telnet-3.03/lib/Net/Telnet.pm


0

Response Number 3
Name: Chris L
Date: October 11, 2002 at 03:11:43 Pacific
Reply:

Thanks for the suggestion, but I’ve never heard of expect, and there is no manual entry for it. Do you have an example? Or where can I get info about it?

Thanks again


0

Response Number 4
Name: Richard
Date: October 11, 2002 at 03:20:15 Pacific
Reply:

Expect is part of Tcl.

I'm haven't used it much so I want' give you an example, but if you type "man expect" into google you'll find plenty.


0

Response Number 5
Name: David Perry
Date: October 11, 2002 at 04:15:08 Pacific
Reply:

http://expect.nist.gov/

#!/usr/bin/expect -f
set username "username"
set password "password"
set n 0
set HOSTNAME "somehost"
while { $n < 5 } {
spawn "/bin/sh"
send "telnet $HOSTNAME\r"
sleep 1
expect "ogin"
send "$username\r"
expect "Password"
send "$password\r"
send "\r\r"
expect {
"Welcome" {
incr pass0
set n 5
set p 0
send "MyCommand\r"
close
}
"from" {
send "id\r"
expect {
$username {
incr pass0
set n 5
close
}
}
}
"login: $" {
set pass1 0
puts stdout "Expect return: $expect_out(0,string)"
puts stdout "Failed login"
send "\x1d\x0d"
expect "telnet"
send "close\r"
send "quit\r"
close
}
}
incr n
}


0

Related Posts

See More



Response Number 6
Name: ademin
Date: October 11, 2002 at 08:19:21 Pacific
Reply:

The easiest way is to use remsh command. It is an HP imlementation of BSD rsh.

for IP in $IPS ;do
remsh $IP -l $user "$1_command; $2command" >file
done


0

Response Number 7
Name: Stefano Giorgi
Date: October 16, 2002 at 09:02:51 Pacific
Reply:

Hi,
if you can't use remsh like me (since I have to telnet to a specifical non-standard port) you can still use telnet but you have to put all of the sentence in a single line, separating all the sentences with new line charachters.
In your case something like this should work:

echo"command1\ncommand2\nexit\n" | telnet $IP

Bye
Stefano


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: Can anyone help with telnet script

help with shell script www.computing.net/answers/unix/help-with-shell-script/7840.html

Help with simple scripting www.computing.net/answers/unix/help-with-simple-scripting/6920.html

Anyone Help?? *Sys Availability* www.computing.net/answers/unix/anyone-help-sys-availability/2503.html