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:


mail_subject="Daily update"


if [ ! -d "$script_path_dir" ];
  echo "Script base directory set does not exist. Creating..."
  mkdir $script_path_dir
  echo "Script base directory set exists. OK"

if [ ! -d "$working_dir" ];
  echo "Script working directory set does not exist. Creating..."
  mkdir $working_dir
  echo "Script working directory set exists. OK"

if [ "$(ls -A $working_dir)" ]; then
 echo "Script working directory is empty. OK"
 echo "Script working directory is not empty. Cleaning..."
 rm -rf $working_dir/*

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" ]
 echo "Master file log not empty. Concatenating..."
 cat $pm_out >> $mail_file
  echo "Master file log empty... ( x )  "

portupgrade -aqyP -l $pu_out

upg_linecount=`wc -l $pu_out`
if [ "$upg_linecount" != "0" ]
  echo "Upgrade file log not empty. Concatenating..."
  cat $pu_out >> $mail_file
  echo "Upgrade file log empty... ( x ) "

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?


Auto-upgrading from cron is kind of a bad idea. You should really read /usr/ports/UPDATING in case there's some sort of manual action that needs to be taken. I'm sure this probably won't be very popular, sorry, but it's true. There's a reason UPDATING exists.

As far as your script goes, you can define BATCH=yes in /etc/make.conf and you won't be prompted for configuration. You may also But that doesn't mean your upgrades will go well.

| improve this answer | |
  • Yeah, after a while I've though about it I've end up with running script "by hand". UPDATING file is really important if you don't want to end up with reinstalling packages because of errors. – Adrian K. Dec 7 '12 at 16:00
  • And batching make config dialog is for me now likely to have because I can tune up settings or uncheck unneeded options preventing to install software which I would not use i.e. Apache, I'm using nginx currently. – Adrian K. Dec 7 '12 at 16:02

If running portsnap from cron, you should really use the cron action, instead of fetch. It sleeps for a random amount of time between 1 second and an hour, before connecting to the server. This is intended to reduce the likelihood of a large number of clients coming online at the same time and hammering the servers.

portupgrade has an option --batch, which aims to process all ports in a fully automated way, so should accept the defaults or the results of a previous invocation of make config. This might be what you are looking for.

| improve this answer | |
  • You, Sir, made my day! Thanks, I'll give it a try. – Adrian K. Nov 27 '12 at 0:58

I've seen the defaults selected in a make config as:

yes '' | make config

yes loops forever printing all its arguments separated with a space and follows them with a '\n'. If no arguments are given, it prints a 'y' followed by a newline every iteration. Here, we've given it an empty argument to cause it to simply print the newlines, which is like hitting enter to accept all the defaults from the from make config prompts.

| improve this answer | |
  • That make config window appears while firing portupgrade -aqyP -l $pu_out in script, so I think that it might be something like yes '' | portupgrade -aqyP -l $pu_out but I don't know it will work. – Adrian K. Nov 26 '12 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.