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/
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
again, real and complex are split into the below set:
ls -l /home/app1/sub-dir1/real
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.
# script: checkfile.sh
# usage: checkfile.sh <dir>
if [ ! -d "$dir" ]; then
echo "$dir is not a directory"
if [ ! -d "$dir1" ]; then
echo "$dir1 is not a directory"
for file in `find "$dir" -name '*.*' -type f`
if [ ! -f $file ];
echo "No file in $dir" | mailx -s "file does not exist" email@example.com
for file in `find "$dir1" -name '*.*' -type f`
if [ ! -f $file ];
echo "No file in $dir1" | mailx -s "file does not exist" firstname.lastname@example.org
$ sh -x checkfile.sh /home/app1/sub-dir1/real
+ '[' '!' -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