UNIX script error message

Greeting!!
I wrote the below script to e-mail me only file names in a specific directory when a file is delayed for some time in a that directory. I am getting unexpected eof error message.
I don't want any email if the folder is blank.(if the condition is not met) I am not getting the email at all.

cd /abc/test/source_test
if [ $(find . -maxdepth 1 -type f -cmin +240 |wc -l) -gt 0 ]; then - print mailx -r "#xyz@email.com" -s "DAP | ALERT | FOUND OLDER FILES IN DROP FILE DIRECTORY" "myfirst.last@email.com" else:fi

Thanks
Hope

There are some issues with the script, mostly missing semicolons, newlines or space and a misplaced -print snippet. After a bit of cleanup:

cd /abc/test/source_test
if [ $(find . -maxdepth 1 -type f -cmin +240 -print |wc -l) -gt 0 ]; then
  #  - print moved to the find command..  
  mailx -r "#xyz@email.com" -s "DAP | ALERT | FOUND OLDER FILES IN DROP FILE DIRECTORY" "myfirst.last@email.com" 
else 
  :
fi

Thanks for the quick reply.
The error is gone now but the email is blank(no file names) even though there are file more than 240 minutes.
Any error in the script?

Regards,
Hope

That is because the find command produces a list of files, but wc -l turns it in just a count (number). Also the information is not being transferred to the mail command.

You could try something like this (put it in a variable first):

delayed_files=$(find . -maxdepth 1 -type f -cmin +240)
if [ "$delayed_files" ]; then
...
fi

Inside the if clause you can reference the variable in the mail command.

1 Like

Many many Thanks.
Hope