-1

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.

Community
  • 1
  • 1

1 Answers1

0

For anyone still interested in answer, here it is.

#!/bin/bash

check=$(find /path/to/folder -ctime -1 -type f)
alert=mail@mail.com

if [[ "$check" ]]
then
    echo "$check" | mail -s "files created" "$alert"
fi

Also make sure to convert CRLF line breaks to Unix style, if it doesn't work and you keep getting unexplained syntax error.

dos2unix /path/to/script

Or follow this link.

Community
  • 1
  • 1