- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Telneting within a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:06 AM
04-26-2002 02:06 AM
Telneting within a script
#!/bin/ksh
REMOTE=server2
(sleep 1
echo username
sleep 2
echo password) | telnet $REMOTE
It works between some servers but not all and when it fails it kicks you out with the message " Connection closed by foreign host."
You can telnet normally between the servers but for some reason it doesn't like my script. Anyone know of any settings that might be preventing this??
Thanks Barbara.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:11 AM
04-26-2002 02:11 AM
Re: Telneting within a script
And consider using Expect. Quite a handy tool for such stuff.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:16 AM
04-26-2002 02:16 AM
Re: Telneting within a script
Thanks but I tried increasing the sleep but it doesn't even seem to get as far as the password, it returns the connection closed straight away! Any other ideas?
Also what is Expect??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:20 AM
04-26-2002 02:20 AM
Re: Telneting within a script
i think the problem is with carriage return
try putting ; at the end of all your script
shell commands.
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:31 AM
04-26-2002 02:31 AM
Re: Telneting within a script
Run it
ksh -x ./<script name>
and watch it run, it may give you and indication as to where the problem is.
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:31 AM
04-26-2002 02:31 AM
Re: Telneting within a script
See http://expect.nist.gov/
Does the account get locked after a few failed logins attempts, by any chance?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 02:42 AM
04-26-2002 02:42 AM
Re: Telneting within a script
I found that this works with HPUX (at least 10.20 and 11.00) but i.e. not with a linux telnet.
Obviously it depends on the security thinking of the programmer. Now linux guys are hardliners in this case, so I found in linux programs that they flush the input stream before they ask for a password (to avoid, that you mistype something and the password appears in cleartext on the screen).
Such a program will never be able to be scripted in this way, because the entire pipe stream is flushed. HP-UX is more tolerant with this, but I do not know if this has been changed in 11.11 or so.
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 05:39 AM
04-26-2002 05:39 AM
Re: Telneting within a script
The solution is the mentioned "expect" program, which was especially designed for problems like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 05:43 AM
04-26-2002 05:43 AM
Re: Telneting within a script
GL,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 06:27 AM
04-26-2002 06:27 AM
Re: Telneting within a script
Here is a simple example extracted from the man pages:
use Net::Telnet ();
my $username = "Clay";
my $passwd = "TOPSECRET";
my $remote_host = "bugs";
$t = new Net::Telnet (Timeout => 30,
Prompt => '/sh\$ $/');
$t->open($remote_host);
$t->login($username,$passwd);
@lines = $t->cmd("/usr/bin/ls -l /etc");
print @lines;
The beauty of this method is that it becomes trivially easy to add error checking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 08:30 AM
04-26-2002 08:30 AM
Re: Telneting within a script
mknod pipe p
executable_file < pipe | telnet nnn.nnn.nnn.nnn > pipe 2>telnet.log
rm pipe
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2002 12:23 PM
04-26-2002 12:23 PM
Re: Telneting within a script
(sleep 5
echo "\r"
sleep 1
echo "login\r"
sleep 1
echo "password\r"
sleep 2
echo "\r") |telnet $REMOTE
Ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2002 08:11 AM
04-30-2002 08:11 AM
Re: Telneting within a script
#!/bin/ksh
REMOTE=server2
(sleep 1
echo username
sleep 2
echo password
sleep 5) | telnet $REMOTE
Your subshell was ending and dropping the telnet connection.
Hope this helps,
rhino
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2002 09:00 AM
04-30-2002 09:00 AM
Re: Telneting within a script
telnet $server <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2002 12:54 PM
04-30-2002 12:54 PM
Re: Telneting within a script
What system and shell did you use to make this work?
Thanks,
rhino