Hi All,
I'm trying to get a script to loop through an array. The array is basically a list of .zip files. I'd like the script to loop through and unzip the zip files contained in the zip file list. When I run the script, it unzip the first zip file correctly, and then stops Any thoughts? Here's the script:
Code:
#!/usr/bin/ksh
clear
# setting up the date to be something a bit more pretty
DATE=`date +%m/%d/%y-%H:%M`
# This date variable is used for directory creation
DATE2=`date +%m%d%y%H%M%S`
# Start a new search in the log files
print "" > logs/recovery.log
print "New Search Started on ${DATE}" >> logs/recovery.log
# User Prompting for email, start date and end date
print " Welcome to the MRR User Recovery Interface"
print ""
print ""
print " Please enter the email address to search for:"
read user
print ""
print " Enter start date to search:"
read sdate
print ""
print "Enter end date of search:"
read edate
print ""
print "I will now search for the email from $user"
print "starting at $sdate and ending at $edate."
print ""
print ""
print "${DATE} Search context email $user" >> logs/recovery.log
print "${DATE} Starting date $sdate" >> logs/recovery.log
print "${DATE} Ending date $edate" >> logs/recovery.log
# Eventually there will be some stuff here to sort the zip files by the sdate and edate and then copy them off to a work directory.
# grab a list of the zip files.
print "Now Getting a file list..."
# The following needs to be changed when putting into production. These file paths
# will *NOT* work. Make sure they are correct! You've been warned.
cd /home/chris/MRR/test/
ls *.zip > /home/chris/MRR/ziplist
print "${DATE} ziplist created" >> /home/chris/MRR/scripts/logs/recovery.log
# This is just for testing purposes, remove or comment out the following line
# cd ../scripts/
# cat ziplist
# Unzipping the files
# To do this, we need to feed the file into an array otherwise ksh will choke.
cat /home/chris/MRR/ziplist|sed 's/.\{4\}$//' >> /home/chris/MRR/dirlist
set -A dirlist $(< /home/chris/MRR/dirlist)
set -A zipfile $(< /home/chris/MRR/ziplist)
for i in $zipfile
do
unzip -qq -d /home/chris/MRR/test/"$dirlist" /home/chris/MRR/test/"$zipfile" >> /home/chris/MRR/scripts/logs/recovery.log
print "name of files in zipfile:" ${zipfile[*]}
done
#