Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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

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.

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
}

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

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

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

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