I require a shell script to find if any new entry of dump files present in a particular directory and to send an email if any new entry exists.I had a crontab to run the script for every 5 min. Below are the file names.
I am not sure whether my way is correct or not.First i manually fill 1.txt how many files are there then it will automatically updates.by comparing i can check the new file is created or not.But the code is not working as expected..
#!/bin/sh
i=`head -1 1.txt`
echo $i
j=`ls -ltr *dump*|wc -l`
echo $j
if [ $i -gt $j ]
then
k=`ls -ltr *dump* | tail -1`
echo $k
exit 1
fi
ls -ltr *dump* | wc -l >1.txt
Note that if a new "dump" file is created after the touch 2.txt command is run and before the find command finishes this file may be listed twice as a new file.
Yes -maxdepth is not supported in all find implementations, we could try the -prune option as I believe this is more widely supported.
If this is run as a cron job you will be notified via email in a similar manor to how you were notified from your ls script above, by default all output from cron jobs is mailed to the jobs owner.