Search code examples
bashcron

is there any way to notify if a new file created in a directory everyday? [Bash-Script]


i do have a directory called /le/df/er everyday in it we save 1 file. is it possible to notify me if a file not or not created one day using

 if
else

what will be the condition?

if []; then
        (echo " File is not Generated Today.") | mailx -s "File not Saved today in $x" ******@gmail.com
else
        echo "Save successful today"
fi

Solution

  • You can use find with -ctime -1 to list files created less than 1 day age.

    So, something like

    if find "$dir" -maxdepth 1 -ctime -1 | grep -q ^ ; then
        echo Created
    fi