[NTLUG:Discuss] Scripting help

Leroy Tennison leroy.tennison at verizon.net
Wed Sep 24 22:24:34 CDT 2014


I'm trying to get telnet to repetitively connect to a newline-delimited 
list of devices.  In other words, if I have device1, device2 and device3 
then what I want is:

telnet device1
telnet device2
telnet device3

I've used three devices as an example but my lists are much longer. For 
reasons too complicated to go into, this has to be done via ssh to a 
Linux machine where I have no file system access (so the list has to be 
pasted into the script interactively).  I've tried numerous variants of 
'for' with no success.  At this point a solution in either bash or ksh 
would be acceptable.  I have tried the following:

for i in device1
device2
device3; do telnet $i; done        The shell tries to execute device2 
and device3

for i in "device1
device2
device3"; do telnet $i; done    All the devices get passed to one 
instance of telnet as parameters

I've tried using grave around the list and setting IFS to a space with 
similar results.  I considered using 'read' but have initially decided 
against it because I don't want the script constrained to a given number 
of list entries.

Any and all ideas welcome.



More information about the Discuss mailing list