1827234 Members
2287 Online
109716 Solutions
New Discussion

non-interactive telnet

 
SOLVED
Go to solution
TopS_1
Occasional Advisor

non-interactive telnet

Hi,

I need to run non-interactive telnet session to HP-UX 11.
I try to use command
(sleep 3;echo oracle;sleep 3; echo ;sleep 3;echo script.sh;sleep 10;echo exit)|telnet atest
When I connect to server with HPUX 10.20 this command works fine but when I try to connect to server with HPUX 11.0, I get
# ./tn.sh
Trying...
Connected to atest.
Escape character is '^]'.
Local flow control on
Telnet TERMINAL-SPEED option ON

HP-UX ATEST B.11.00 A 9000/800 (te)

login: root
Password: Connection closed by foreign host.
# Trying...
Connected to atest.
Escape character is '^]'.
Local flow control on
Telnet TERMINAL-SPEED option ON

HP-UX ATEST B.11.00 A 9000/800 (te)

login: root
Password: Connection close by foreigh host

I tried to change timeout value for telnetd daemon (-z option)in inetd.conf file but result was same.
7 REPLIES 7
Paula J Frazer-Campbell
Honored Contributor

Re: non-interactive telnet

Hi Olga


If I remember correctly there is a script here:-


http://forums.itrc.hp.com/cm/QuestionAnswer/0,,0x026250011d20d6118ff40090279cd0f9,00.html



Paula
If you can spell SysAdmin then you is one - anon
Rainer von Bongartz
Honored Contributor
Solution

Re: non-interactive telnet

You need another solution for this:

take a look at the expect software (http://expect.nist.gov/)

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications

Regards
Rainer



He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Paula J Frazer-Campbell
Honored Contributor

Re: non-interactive telnet

Olga

Have you looked at rlogin for this task.

Man rhosts and man rlogin.

I would also watch the security aspect as I see you are trying to login at root level. Test on a test server as if it goes wrong on your script it can make a mess of the server you are loging in to.


Paula
If you can spell SysAdmin then you is one - anon
Bill McNAMARA_1
Honored Contributor

Re: non-interactive telnet

you could possibly mess around with the non-interactive ftp scripts that you can find all over this forum.

Later,
Bill
It works for me (tm)
Ron Kinner
Honored Contributor

Re: non-interactive telnet

Normally the default is not to allow root to login remotely. Try it with a different user first. If that doesn't work then:

Try adding \r at the end as per the following script (I've cleaned it up by replacing the IP address, login and password and removed the actual commands but we use it every day):

REMOTE=A.B.C.D
(sleep 5
echo "\r"
sleep 1
echo "login\r"
sleep 1
echo "password\r"
sleep 5
echo "some command\r"
sleep 1
echo "another command\r"
sleep 5
echo "q\r"
sleep 1
echo "exit\r"
echo "\r") |telnet $REMOTE

Ron
Bill Douglass
Esteemed Contributor

Re: non-interactive telnet

I would recommend installed ssh on your box:

http://www.software.hp.com/cgi-bin/swdepot_parser.cgi/cgi/displayProductInfo.pl?productNumber=T1471AA
fpr the HP-supported version, or

http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/openssh-3.6.1p1/
if you want to roll your own copy.

You can set up private/public keys for root, and run commands on the remote host via:

ssh -l root -i /path/to/root/private_id /some/command

More secure than embedding a root password in a script, plus you get encryption across the network.

See man pages for ssh, ssh-keygen.
John Meissner
Esteemed Contributor

Re: non-interactive telnet

I use expect to do non-interactive telnet sessions. it's extreemly easy to do. just type:
autoexpect -f telnet hostname
then proceed to do what you want to. when done it generates a script for you. you will need to edit this script and remove some of the extraneous text such as the time and date... I'm attaching an example script with my username, password, and hostname changed.
All paths lead to destiny