Thread: what does the below script do?
07-03-13, 08:54 #1Registered User
- Join Date
- Jul 2013
Unanswered: what does the below script do?
am completely new to shell scripting and assigned a task where the script needs to be modifies to achieve some task,so priory am trying to get what the existing script is performing,Please let me understand the highlighted portions
echo "Begin unzip at `date`"
for i in $SOURCE_DIR/*
file_lookup_name=`echo $file_name | cut -d'_' -f1`[/COLOR]
email_address=`grep -i /$file_lookup_name/ $SOURCE_MAPPING_FILE | grep -v "^#" | cut -d" " -f 3`
filename_len=`basename $i | wc -m`
echo "The filename is $file_name and its length is $filename_len"
if [ "$filename_len" -gt 2 ]
mapping=`grep -i /$file_lookup_name/ $SOURCE_MAPPING_FILE | grep -v "^#" | cut -d" " -f 2`
mapping_length=`echo $mapping | wc -m`
echo "Processing File $i"
if [ "$mapping_length" -gt 1 ]
# Test whether zip file is GOOD or BAD
unzip -t $i > /tmp/$file_name.txt 2>&1
zip_file_check=`tail -1 /tmp/$file_name.txt | cut -c 1-18`
if [ "$zip_file_check" = "No errors detected" ];
echo "File is Good"
unzip -l $SOURCE_DIR/$file_name>/tmp/$file_name2.txt
line_count=`wc -l </tmp/$file_name2.txt`
line_count2=` expr $line_count - 5`
sed -n '4,$p' $tmp_dir | head -$line_count2 | grep -v ".*\[HS-[0-9]*].*">/tmp/$file_name3.txt
count=`wc -l </tmp/$file_name3.txt`
mai=" File $file_name has $count reports"
echo $mai | mailx -s " $file_name Stats " -c "email@example.com" $email_address
echo "Mail Sent"
echo "FILE $file_name is good and has been processed and has $count reports and mail has been sent to $email_address at `date`" >> $COUNT_LOG
unzip $i -d $destination_dir
chmod -R 664 $destination_dir/*
echo "FILE $file_name has not been processed as it failed in unzip" | mailx -s "Relay Server File Processing Error" firstname.lastname@example.org -- -f email@example.com
echo "FILE $file_name has not been processed as it failed in unzip at `date`" >> $ERROR_FILE
echo "FILE $file_name is not good and has not been processed as it failed in unzip and mail has been sent to $email_address at `date`" >> $COUNT_LOG
rm -f /tmp/$file_name.txt
rm -f /tmp/$file_name2.txt
rm -f /tmp/$file_name3.txt
mv $i $ARCHIVE_DIR/$file_name
echo "No Mapping present for $i" | mailx -s "Relay Server File Processing in BOXI PROD" firstname.lastname@example.org
echo "No Mapping present for $i"
echo "No files to Process, sleeping"
07-03-13, 14:01 #2Registered User
- Join Date
- Jun 2003
- West Palm Beach, FL
What highlighted portion(s)?
. . . do file_name=`basename $i` (1) file_lookup_name=`echo $file_name | cut -d'_' -f1` (2) . . .
(2) "cut" extracts the first portion (field) of the file name split by the '_' separator
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb