This is not homework I am new to UNIX and want to try this Monitoring a file demo
If this is the wrong forum please move it - im new to the forums
$1 = the file to be monitored
$2 = the time for the file to sleep
If the file gets changed (using -nt) it will send my username mail saying its changed it. The problem im having is it goes into an endless loop, im just learning the while loop so im guessing its that. Also I dont understand the whole mail code - how do I input subject and stuff.
#!/bin/bash
if [ $# -eq 0 ] ; then
echo "enter <file> <time>"
exit 1
fi
if [ ! -e $1 ] ; then
echo " please enter an existing file"
exit 2
fi
if [ "$2" = "" ] ; then
echo " no argument 2"
exit 3
fi
if [ $2 -lt 10 ] ; then
echo " please enter a number higher than 10"
exit 4
fi
while [ $2 -ge 10 ] ; do
if [ $1 -nt ] ; then
sleep $2
mail $LOGNAME
else
echo "file unchanged"
fi
done
exit 0