Have you considered inotifywait(1) provided by the inotify-tools package on some distributions, this can run your script whenever a file appears in specified directories eg:
inotifywait -m /your/upload/file/path -e create -e moved_to |
while read dir action file
do
# run your script passing the directory, filename and action
/usr/local/bin/yourscript $dir $file $action
done
I did a simple script to monitor after installing inotify-tools, and place it in cron:
@reboot /root/shellDetector/shellDetect.sh
With grep:
ps -eaf | grep shellDetect.sh | grep -v grep
The script in not running on boot
#!/bin/sh
inotifywait -m /home/uvid/www/Uploads -e create -e moved_to |
while read -r dir action file; do
echo "The file '$file' appeared in directory '$dir' via '$action'"
# do something with the file
done
Did cron log the script's start? Add some logging to your script, so you know that it started, and why and when it exited, either to syslog, or a individual log file.
A issue I see a lot with cron is that the environment is not set as it is during a normal login. Particularly the PATH environment variable.
With your particular script I'm guessing that inotifywait is not being found. You could either set PATH at the top of your script or fully qualify the command like this /usr/bin/inotifywait .
Try setting PATH to a reasonable value at the top of that script. Cron does not execute /etc/profile or other login scripts so PATH is likely to be unset then the script is failing to find external commands like find and mail .
#!/bin/sh
inotifywait -m /home/uvid/www/Uploads -e create -e moved_to |
while read -r dir action file; do
echo "The file '$file' appeared in directory '$dir' via '$action'"
sh /root/Scripts/Misc/shellDetect.sh
echo "Hello new file is here | /usr/bin/mail -s "new file" EMAIL
done