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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script with For loop problem

Status
Not open for further replies.

jdaily

Technical User
Jan 19, 2004
53
0
0
US
I have a script, see code below, that gets the variables from a program that the script is run from. The variable MARKET contains an array of market names (5 to be exact).

The first two steps in the script work perfect but when I get to the for loop it starts working great on the first pass but then the rest of my script, after the for loop, starts running and then when the for loop goes to the next market it starts the entire script over again.

Code:
#!/usr/bin/sh


FILE_TIMESTAMP=${1}
TRIMESTER=${2}
DATAMONTH=${3}
MARKET=${4}
LOG_FILE_PATH=${5}
EXTRACT_FILE_PATH_ZS=${6}

#Change DIR to ZS Extracts Directory.
  cd ${EXTRACT_FILE_PATH_ZS}


#Create control file for all files.
  wc -l *${FILE_TIMESTAMP}* > ZS_ALL_${TRIMESTER}_DM${DATAMONTH}_${FILE_TIMESTAMP}.control


#MARKETS
#Loop through all the markets listed in the job parameters
# to create the control files, gzip the txt files and tar them together and then create the log file.
 for m in ${MARKET}; do
     grep -i SALES_US_${m} ZS_ALL_${TRIMESTER}_DM${DATAMONTH}_${FILE_TIMESTAMP}.control > ZS_US_${m}_${TRIMESTER}_${FILE_TIMESTAMP}.control
     gzip *SALES_US_${m}*${FILE_TIMESTAMP}*txt
     tar -cvf ZS_MARKET_SALES_US_${m}_${TRIMESTER}_DM${DATAMONTH}.tar *US*${m}*${FILE_TIMESTAMP}*
     tar -tvf ZS_MARKET_SALES_US_${m}_${TRIMESTER}_DM${DATAMONTH}.tar > ZS_MARKET_SALES_US_${m}_DM${DATAMONTH}_${FILE_TIMESTAMP}.log
 done



#OUTLET NON-RETAIL SALES
#Create the Outlet Non-Retail Sales control file
  grep -i OUTLET_NON_RETAIL_SALES ZS_ALL_${TRIMESTER}_DM${DATAMONTH}_${FILE_TIMESTAMP}.control > ZS_OUTLET_NON_RETAIL_SALES_${TRIMESTER}_${FILE_TIMESTAMP}.control

#Gzip the Outlet Non-Retail Sales files
  gzip *OUTLET_NON_RETAIL_SALES*${FILE_TIMESTAMP}*txt

#Tar the Outlet Non-Retail Sales files
  tar -cvf ZS_OUTLET_NON_RETAIL_SALES_${TRIMESTER}_DM${DATAMONTH}.tar *OUTLET_NON_RETAIL_SALES*${FILE_TIMESTAMP}*gz

#Create the Outlet Non-Retail Sales log file
  tar -tvf ZS_OUTLET_NON_RETAIL_SALES_${TRIMESTER}_DM${DATAMONTH}.tar > ZS_OUTLET_NON_RETAIL_SALES_DM${DATAMONTH}_${FILE_TIMESTAMP}.log

Thank you in advance for any advice!!

John
 
Try
Code:
FILE_TIMESTAMP=${1}
TRIMESTER=${2}
DATAMONTH=${3}
[b]MARKET="${4}"[/b]
LOG_FILE_PATH=${5}
EXTRACT_FILE_PATH_ZS=${6}
so that 'MARKET' gets set to all the array, not just the first entry.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top