Hi,
I have a script to process files coming in at different time intervals under multiple nested directories. Each directory set is considered as an app. Different cron jobs have been set for these apps to process the files.
the dir structure for say app1 is something like this
ls -l /home/app1/
sub-dir1
sub-dir2
sub-dir3
and each sub-dir has another set of dirs like this(The below dirs are same for all the sub-dirs):
ls -l /home/app1/sub-dir1
real
complex
again, real and complex are split into the below set:
ls -l /home/app1/sub-dir1/real
raw
pending
wip
done
error
The file processing is based on staging concept. file(s) come(s) under raw/pending then are/is moved one by one to "wip" to process and on success is moved to "done" or to "error" otherwise.
My main target is to set up a script to be called inside my main script, which checks for files in each of the raw/pending directories in all the sub-dirs of an app i.e. my script should check in this order:
/home/app1/sub-dir1/real/raw/*.* or /home/app1/sub-dir1/real/pending/*.*
/home/app1/sub-dir2/real/raw/*.* or /home/app1/sub-dir1/real/pending/*.*
/home/app1/sub-dir3/real/raw/*.* or /home/app1/sub-dir1/real/pending/*.*
after it has checked in all the sub-dir's it should send a mail consiting of those sub-dir's which haven't received files for today.
I wrote a script to include general if-else condition to check for files. When there is no file found it should send same via mail but post the "find condition" the script simply exits.
#!/bin/bash
# script: checkfile.sh
#
# usage: checkfile.sh <dir>
#################################
dir=$1/pending
dir=$1/raw
if [ ! -d "$dir" ]; then
echo "$dir is not a directory"
exit 1
fi
if [ ! -d "$dir1" ]; then
echo "$dir1 is not a directory"
exit 1
fi
for file in `find "$dir" -name '*.*' -type f`
do
if [ ! -f $file ];
then
echo "No file in $dir" | mailx -s "file does not exist"
xyz@nozone.com
fi
done
for file in `find "$dir1" -name '*.*' -type f`
do
if [ ! -f $file ];
then
echo "No file in $dir1" | mailx -s "file does not exist"
xyz@nozone.com
fi
done
output:
$ sh -x checkfile.sh /home/app1/sub-dir1/real
+ dir=/home/app1/sub-dir1/real/pending
+ dir1=/home/app1/sub-dir1/real/raw
+ '[' '!' -d /home/app1/sub-dir1/real/pending ']'
+ '[' '!' -d /home/app1/sub-dir1/real/raw ']'
++ find /home/app1/sub-dir1/real/pending -name '*.*' -type f
++ find /home/app1/sub-dir1/real/raw -name '*.*' -type f
Please advice where i am doing it wrong
Thx in advance