I'm trying to set up cron to run the following command inside a script:
find /path/to/folder -ctime -1 -type f
and send a mail if there were any created files in a specific folder for the past day. So far I have come up with this:
#!/bin/bash
check=$(find /path/to/folder -ctime -1 -type f)
alert=mail@mail.com
if [ "$check" -eq 0 ]
then
mail -s "files created" "$alert"
fi
Problem is that I cannot execute the script even though shell cheker says there are no errors. It gives me syntax error: unexpected end of file.
I have searched the web long enough to realise that other solutions like MAILTO and MAILFROM or scripts like this won't work. I have also looked into this thread but nothing seems to work and if I may add that this is for CentOS 6 in case it makes any difference.
Any help will be most appreciated. Thanks.