[NTLUG:Discuss] Scripting help
Eric Schnoebelen
eric at cirr.com
Fri Sep 26 10:03:05 CDT 2014
Leroy Tennison writes:
- 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).
Is the script hosted locally or on the system you're using SSH
to connect too?
If the script, and the list of devices are in files locally,
something like this could work:
for h in host1 host2.. ; do
ssh gateway telnet $h
done
If the script is remote, but can take an argument set (aka, it
looked like this:
for h in "$@"; do
telnet $h
done
)
it could be called as
ssh gateway <script> $(cat <devices>)
- 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.
Why would using read constrain you to a limited number of
entries? Here's a small shell program to keep gobbling the read
values, and turn it into a single variable that can be parsed by
the for subcommand:
hosts=""
while read host ; do
hosts="$hosts '$host'"
done
for h in $hosts; do
telnet $h
done
--
Eric Schnoebelen eric at cirr.com http://www.cirr.com
Five boxes preserve our freedoms:
soap, ballot, witness, jury, and cartridge
More information about the Discuss
mailing list