Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using arguments in a config file

Status
Not open for further replies.

Skywalker1957

Technical User
Nov 21, 2008
85
US
Have a quick question. I need to configure a file with arguments for my robotic libraries to run an inventory check command. How do I loop through the list and use my multiple arguments from each line.


Example config file robots.conf

# type num host
TLD 0 nbu001
TLD 1 nbu002
TLD 2 nbu003

I'm guessing this would need some kind of for loop with awk that could substitute the three fields above as arguments into my command line right?

Unfortuantely I don't know how to assign variables within awk, but it seems to me this ought to be easy enough to do on one line. Oreilly's hasn't been too helpful to me yet.

This is the command I'm trying to use to insert the arguments above into.

Example of tape_check.sh
#Run mismatch/checker command
vmcheckxxx -rt $type -rn $num -rh $host |mailx -s "Robot $num on $host tape check - `date`" email_address

Any help would be greatly appreciated! Thanks!
 


Try this:
Code:
grep -v '^#' robots.conf|\
while read type num host
do

  vmcheckxxx -rt $type -rn $num -rh $host |mailx -s "Robot $num on $host tape check - `date`" email_address
done
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Try running this script. It does not use awk, but instead the Korn shell. The script assumes that each field will be separated by 1 or more spaces and that there are no embedded spaces within the fields.

I tested the script with the sample data file it creates. So just cut and paste it into a file and run it as is.


#!/bin/ksh

infile_name="args.dat"
(
echo "TLD 0 nbu001"
echo "TLD 1 nbu002"
echo "TLD 2 nbu003"
echo "TLD 3 nbu004"
echo "TLD 4 nbu005"
) > $infile_name # Create a sample input file for testing purposes

num_recs=$(wc -l < $infile_name) # Get the number of lines in input file
line_num=0

while [ "$line_num" -lt "$num_recs" ]; do
let line_num=$line_num+1
head -$line_num $infile_name | tail -1 | read type num host # Read current line in file and parse into $type $num $host
echo "type=$type num=$num host=$host"
done # while
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top