Hopefully there are some linux gurus around.
I'm writing a bash script to compare a logfile to the contents of a directory. The logfile gets written on first running the script. Every subsequent run compares the logfile to the directory, tells the user when a file from the log is missing from the directory, and the rewrites the logfile. Its so specific because its just for my scripting lab.
My problem lies in the red colored line. I need to have the script compare the file from the log to the directory. If it can't find it print "$file missing from directory $DIR", flag a file as missing (to prevent the "no files missing" message), and continue with the loop. Our professor likes to leave a few things to us to figure out, and apparently nesting a command as the test in an if statement was one of them. Anyone know the syntax for it? The closest thing I could figure out invloved curly braces, but it throws an error:
./dirlog: line 20: syntax error near unexpected token `then'
./dirlog: line 20: ` if { ! find $file } ; then'
Any ideas?
#! /bin/bash
FILEMSNG=0
DIR=$1
if [ ! -d $DIR ] ; then
echo "usage: dirlog directory_name"
exit
fi
cd $DIR
if [ ! .logfile ] ; then
echo ".logfile created for $DIR"
ls > .logfile
exit
fi
for file in .logfile
do
if { ! find $file } ; then
echo "$file missing from directory $DIR"
FILESMNG=1
fi
done
if [ FILEMSNG -eq 0 ] ; then
echo "no files missing from directory $DIR"
fi
rm .logfile
ls > .logfile
echo ".logfile updated for directory $DIR"