[nzlug] Telnet in all it's... hmm.... greatness?

Kealey, Martin, ihug-NZ Martin.Kealey at vodafone.com
Tue Jun 10 12:18:07 NZST 2008


Nevyn wrote:
> 	( sleep 1
> 	  echo username ; sleep 1 ; echo password ; sleep 1
> 	  commandToTryAndStartPPP ; sleep 10 ; echo logout
> 	) |
> 	telnet $ROUTER
> 	kill `pidof telnet`
> I don't think this is such a good idea. Need to
> figure out how to a) exit cleanly or b) grab the PID of just this
> telnet session or c) to leave the session open and have the script
> just use that session everytime it wants to communicate with the
> router

<OB1>Use netcat, Luke</OB1>

Netcat automatically exits when the *network* connection closes -- which it generally will if send "logout".

It also doesn't need funny time-delays to get the input to go at the right time.

Apropos getting the pid:

	echo $blahblah | telnet $host &
	pid=$!
	echo do other stuff
	kill -HUP $pid

The "$!" gives you the PID of the most recently started background process.

(In the case of a pipeline, the PID of the right-most command, which is usually the one you want because it's output is what gets suspended.)

-Martin
-- 
(Apologies to the list for the ridiculous verbage that appears below this line; please remove it when quoting any reply.)
-----------------------------------------------------------------------------------------------
Have you seen our website?.... http://www.vodafone.co.nz

Manage Your Account, check your Vodafone Mail and send web2TXT online: http://www.vodafone.co.nz/myvodafone

CAUTION: This correspondence is confidential and intended for the named recipient(s) only.
If you are not the named recipient and receive this correspondence in error, you must not copy,
distribute or take any action in reliance on it and you should delete it from your system and
notify the sender immediately.  Thank you.

Unless otherwise stated, any views or opinions expressed are solely those of the author and do
not represent those of Vodafone New Zealand Limited.

Vodafone New Zealand Limited
20 Viaduct Harbour Avenue, Private Bag 92161, Auckland 1030
Telephone + 64 9 355 2000
Facsimile + 64 9 355 2001



More information about the NZLUG mailing list