I've created an custom clamscan(clamav) in bash and when I run it in my shell everyhing is fine, but if I run it in a cron, it can't create the log file.
This are the errors:
- /root/Scripts/clamscan : line 9: /var/log/clamscan/weekly/clamscan-Test-2014-09-16.log: No such file or directory
- /bin/bash: /root/Scripts/clamscan: Permission denied
- Also I get emails from cron asking if it's: Null message body;hope that's ok that this is a mail with no header? Or something.
- Before the "if it's ok mail" I get an empty email, with no message
If I run the script in a shell, it creates the log file no problem.
Questions:
- What do I have to do with my
bash scriptso it can write the appropriate files? - Why do I get these errors?
Here is the script:
#!/bin/bash
FILENAMEDATE=$(date +"%F")
/usr/bin/clamscan -i -r --log=/var/log/clamscan/weekly/clamscan-Test-$FILENAMEDATE.log /home/Username/Downloads >/dev/null 2>/dev/null
if [ $? -gt 0 ];
then
SUBJECT="Virus Report for `uname -n`, `date +%m-%d-%Y`"
mail -s "$SUBJECT" 'Email' < /var/log/clamscan/weekly/clamscan-Test-$FILENAMEDATE.log
fi
Here is /etc/crontab:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO="Email"
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
56 13 * * * root /bin/bash /root/Scripts/clamscan