I have a small part of a bash script I am working on that needs to check for the number of a specific file type (*.spl) in a directory. If the files detected are zero (0), then the echo message needs to write to a logfile the message why and then break / exit thus stopping the script.
So far the following isn't working as expected:
# Count *.spl files found to process
for file in $( ls -1 $dump_dir/*.spl 2>/dev/null )
file_count=`expr $file_count + 1`
if [ $retval -ne 0 ]
echo -e " Aborting file transfer (No SPL files found) at `date "+%D %k:%M:%S"`" >> $logfile
echo -e " Found $file_count files to process at `date "+%D %k:%M:%S"`" >> $logfile
It keeps showing the same thing via 'set -x' output:
++ ls -1 '/home/tims/transfer/*.spl'
++ date '+%D %k:%M:%S'
+ echo -e ' Found 0 files to process at 09/19/12 13:23:40'
In the log file it is showing this:
Starting Daily TIMS Transfer at 09/19/12 13:23:40
Found 0 files to process at 09/19/12 13:23:40
The intent is that if no files are found, the script needs to fully stop.
But it keeps the script going, attempting to zip up zero files, etc.