Looking for some help with my bash script. I am trying to write this shell script to do the following:
-
find files in a dir named:
server1-date.done
server2-date.done
server3-date.done
...
server10-date.done -
print to a
listA - find files in a dir (*.gz) and print to a
listB - if
listAhas a count of10(basically found 10.donefiles), then
proceed with the moving the files inlistBto its new directory - after moving the files from
listB, then remove the old directory which is similarly named (server1-date,server2-date, …) and the .done files.
So far, I have this in the works. I can’t get the condition for the if section working. I don’t think I coded that correctly. Any code suggestions, improvements, etc would be appreciated. Thanks.
#Directories
GZDIR=/mydumps/mytest
FINALDIR=/mydumps/mytest/final
FLGDIR=/backup/mytest/flags
export GZDIR FINALDIR FLGDIR
#lists
FLGLIST="/mydumps/mytest/lists/userflgs.lst"
GZLIST="/mydumps/mytest/lists/gzfiles.lst"
export FLGLIST GZLIST
#Find files
find $FLGDIR -name \*.done -print > $FLGLIST
find $GZDIR -name \*.gz -print > $GZLIST
#Get need all (10) flags found before we do the move
FLG_VAL =`cat $FLGLIST | wc -l`
export $FLG_VAL
if [ "$FLG_VAL" = "10" ]; then
for FILE in $GZLIST
do
echo "mv $GZLIST $FINALDIR" 2>&1
for FLAG in $FLGLIST
do
echo "rmdir -f $FLAG" 2>&1
done
done
else
echo "Cannot move file" 2>&1
exit 0
fi
I do not know if this will work, but it will fix all the obvious problems: