I've been recently try to write a script to automate checks for new version of ports and software installed on my FreeBSD server. This script is added to root's crontab and fires daily. If I run it from sudo /path/to/script it goes forward decently sending mail with content on my email address. If it's run by cron I get an empty mail. I think that the reason might be that while update sometimes window appears (from make config i think) with compilation options, but I might be wrong. Here's the script:
#!/usr/local/bin/bash
# DIRECTORIES SETUP
script_path_dir="/tmp"
working_dir="$script_path_dir/portsupgradescript"
# FILES SETUP
mail_file="$working_dir/mail.txt"
mail_address="MY_MAIL_ADDRESS"
mail_subject="Daily update"
pm_out="portmaster_log.txt"
pu_out="portupgrade_log.txt"
# START
if [ ! -d "$script_path_dir" ];
then
echo "Script base directory set does not exist. Creating..."
mkdir $script_path_dir
else
echo "Script base directory set exists. OK"
fi
if [ ! -d "$working_dir" ];
then
echo "Script working directory set does not exist. Creating..."
mkdir $working_dir
else
echo "Script working directory set exists. OK"
fi
if [ "$(ls -A $working_dir)" ]; then
echo "Script working directory is empty. OK"
else
echo "Script working directory is not empty. Cleaning..."
rm -rf $working_dir/*
fi
rm -rf $pm_out
rm -rf $pu_out
rm -rf $mail_file
/usr/sbin/portsnap fetch update && \
/usr/local/sbin/portmaster -L --index-only | egrep '(ew|ort) version|total install' > $pm_out
linecount=`wc -l $pm_out | awk {'print $1'}`
if [ "$linecount" != "0" ]
then
echo "Master file log not empty. Concatenating..."
cat $pm_out >> $mail_file
else
echo "Master file log empty... ( x ) "
fi
portupgrade -aqyP -l $pu_out
upg_linecount=`wc -l $pu_out`
if [ "$upg_linecount" != "0" ]
then
echo "Upgrade file log not empty. Concatenating..."
cat $pu_out >> $mail_file
else
echo "Upgrade file log empty... ( x ) "
fi
echo "Seding mail report..."
cat $mail_file | mail -s "$mail_subject" "$mail_address"
Is there any way to select defaults on "make config" window so this would be not a showstopper? Or maybe I should run this script sudoed in user's cron, not root's?