Thursday, October 29, 2015

permissions - Hourly Clamscan cron script failes at reading file list

I've this piece of code located in /etc/cron.hourly/hourlyclamscan.




#!/usr/bin/bash
# Create Hourly Cron Job With Clamscan

# Directories to scan
SCAN_DIR=/home/transmission/Downloads

# Temporary file
LIST_FILE=`mktemp /tmp/clamscan.XXXXXX`

# Location of log file

LOG_FILE=/var/log/clamav/hourly_clamscan.log

# Make list of new files
/usr/bin/find "$SCAN_DIR" -type f -mmin -60 -fprint ${LIST_FILE}
# Scan files and remove infected
/usr/bin/clamscan -i -f ${LIST_FILE} --remove > $LOG_FILE

# If there were infected files detected, send email alert
if [ `cat ${LOG_FILE} | grep Infected | grep -v 0 | wc -l` != 0 ]
then

echo "$(egrep "FOUND" $LOG_FILE)" | /bin/mail -s "VIRUS PROBLEM" -r clam@nas.local #####@#####.##
fi
exit


When I run it from the terminal, it give no error.



However, when cron runs the script, it sends an error to the root mailbox:
ERROR: --file-list: Can't open file /tmp/clamscan.MLXep5




The file is created by find and owned by root (permission 600). The cron job is also run as root, so I assume permissions should not be an issue (or is it?).

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...