[NTLUG:Discuss] Scripting help
Leroy Tennison
leroy.tennison at verizon.net
Tue Oct 7 00:00:10 CDT 2014
Eric's approach worked, thanks:
hostlist=""
while read host; do hostlist="$hostlist $host"; done
(paste the line-delimited lists of hosts followed by a Ctrl-D here)
for i in $hostlist; do telnet $i; done
On 09/26/2014 09:50 PM, Leroy Tennison wrote:
> Thanks for your reply. In response to your first question, the script
> is hosted on the system I'm connecting to via ssh. More specifically,
> the local host is Windows, the ssh client is Putty and only the remote
> system is Linux. I do not have file system write access on the Linux
> machine which makes things challenging. I write the script
> interactively, pasting in my list at the appropriate place.
>
> I "played around" with your final script and may have come up with a
> solution:
>
> hosts="host1
> host2
> host3";
> for i in $hosts; do echo aaa $i bbb; done (I'm testing
> from home where no host list exists so 'echo aaa $i bbb' shows the
> command)
>
> What I got was:
>
> aaa host1 bbb
> aaa host2 bbb
> aaa host3 bbb
>
> which looks like what I want. A test Monday will tell...
>
> On 09/26/2014 10:03 AM, Eric Schnoebelen wrote:
>> 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
>>
>> _______________________________________________
>> http://www.ntlug.org/mailman/listinfo/discuss
>>
>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list