I have a server that receives backup files from several servers. Each server has its own directory to scp their files into, some of the files are received as .tar files and need to be compressed before being dumped. When the scp of the tar file is complete a file named 'flag' is also sent to indicate that the scp of the zip file is complete.
The following script is supposed check for any existing flag files and .tar files and run bzip2 on any .tar files found.
The specific problem is that, on the first while loop if no flag or tar file is found the second loop is not initiated. If the data for the first loop exists then both loops run as expected. (Currently only data for two servers are included for testing).
I've looked and looked for the error in my logic and it eludes me. Could someone point out my blind spot?
The data file being read is appended after the code.
Thanks
Thumper
Code:
#!/bin/bash
#
# set -n
set -x
##########################################################
####################### FUNCTIONS ######################
##########################################################
file_exists () {
echo "ENTERING FILE_EXISTS"
echo "the value of \$1 is ${1}"
echo "the value of \$2 is ${2}"
if [ -e ${1} ] #test for the flag file
then
if [ -e ${2} ] #test for the .tar file
then
`bzip2 ${2}` #bzip the .tar file
`rm ${1}` #remove the flag file
else #no .tar file found
mail -s "No ${2} file found" thumper@somewhere.net
fi
else #no flag file found
mail -s "No ${1} file found" thumper@somewhere.net
fi
return 0
}
#### end
##########################################################
#################### MAIN ################################
##########################################################
while IFS=: read dir sname flag ext
do
VAL_1="/$dir/$sname/$flag"
VAL_2="/$dir/$sname/$ext"
echo ${VAL_1}; echo ${VAL_2}
# echo "Calling file_exists"
file_exists ${VAL_1} ${VAL_2}
# echo "Exited file_exists"
echo "VAL_1 is ${VAL_1}"
echo "VAL_2 is ${VAL_2}"
echo "\$? is $?"
done < /root/scripts/bz-data
# End of script
DATA FOR READ STATEMENT
/root/scripts/bz-data
archive:yoda:flag:*.tar
archive:chewy:flag:*.tar