Operating System - Linux
1828208 Members
2333 Online
109975 Solutions
New Discussion

Expect/For-While Loop or Source

 
SOLVED
Go to solution
Michael Lyon
Frequent Advisor

Expect/For-While Loop or Source

I have attached the following script, and was wondering how I would go about adding either an entry for Source=RouterIP (Router IP being any file containing the addresses of routers I'm trying to manage configs for) or...

How would I go about doing a for-while loop that does queries against a range of hosts from DNS?

Of course, the Source option would be easier, but how do I integrate it into my existing script, which works great, but for only ONE host?

Thanks!

5 REPLIES 5
Michael Williams_6
Trusted Contributor

Re: Expect/For-While Loop or Source

Hi, being an old-fashioned ksh person, I'd wrap that script in a ksh script.

You'll need a file with the correct 5 arguments, or however many they were, seperated by a space, or a tab might work, then you can do the following:

#!/bin/ksh
for $line in `cat /path/to/config/file`
do
/path/to/your/script $line
done
Michael Williams_6
Trusted Contributor

Re: Expect/For-While Loop or Source

Arse, that first line should have read:

for line in `cat /path/to/config/file | grep -v "^#"`
Roberto Polli
Trusted Contributor
Solution

Re: Expect/For-While Loop or Source

Michael,
that's

for line in `grep -v "^#" /path/to/config/file`

Peace, R.
Michael Williams_6
Trusted Contributor

Re: Expect/For-While Loop or Source

Just as good, I have no idea why I always cat and pipe to grep - habit I guess!
Michael Lyon
Frequent Advisor

Re: Expect/For-While Loop or Source

Thanks for the help...it is greatly appreciated.