Gentoo Wiki


This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other



This TIP will introduce a short script that can do the following things for you:

The script is intended to be run on a regular basis (eg weekly) by your cron-daemon.

So, you won't have to run 'emerge --sync' by hand, wait till it's finished, type 'emerge -avuDN world', wait for the dependencies to be calculated, review the list of packages and after this start the merge or even decide you don't see any required updates. Instead you will receive a mail, including all revelant news, and can immediately start the merge or decide to update next week.

Also your portage tree will always be up-to-date and distfiles you haven't recently needed are automatically deleted.


This article details how to get notifications of updates automatically but does not actually perform the updates. You should not update packages automatically by cronjob. The main reason for this is that if, for example, PAM is updated and requires configuration updates, but they aren't performed correctly, you could easily be locked out of all logins to your system. You have been warned!


All you will need is:


Get the script

First become root and copy/paste the script to your system:

jane ~#
vi /usr/local/bin/pretend-system-update.shImage:CursorOFF.gif

# Files in /usr/portage/distfiles that have not been useful since DISTFILES_MAX_AGE days will be deleted

# Recipient of system-software-update-report-mails ;) (can be any valid mail address)
# The text you would like to see as the mail's subject
MAIL_SUBJECT="Weekly system software update report for $(hostname -f) and the week of $(date '+%B %d')"

# If you want the list of packages to be encased in lines set this to '0', otherwise to your favorite number
# In case you want to see all the USE flags this is '0' for you, otherwise any number

(echo -e "This is the pretend-system-update script on $(hostname -f); $(date).\n"

echo -n "Updating portage tree ... "
emerge --sync &> /dev/null && echo "done" || echo "failed"

cd /usr/portage/distfiles
echo -n "Trashing out-dated distfiles ... $(du -sch dummy_file $(find -atime +${DISTFILES_MAX_AGE} -print | grep -vx ".") 2>&1 | tail -n 1 | sed -r 's/\s*total//g') to be deleted ... "
find -atime +${DISTFILES_MAX_AGE} -delete && echo "done" || echo "failed"

echo -e "\nThe script does _not_ install any packages; it just informs about available updates:"
test ${SHOW_SPLITTERS} -eq 0 && echo -e "=======================================================================\n" || echo
test ${SHOW_USE_FLAGS} -eq 0 && emerge -pvuDNq world || emerge -puDNq world; SUCCESS=$?
test ${SHOW_SPLITTERS} -eq 0 && echo -e "\n======================================================================="
if [ ${SUCCESS} -eq 0 ]; then
	echo -e "\nTo install these package updates just type 'emerge -uDN world'.\n\n" 
	echo -e "\nI'm sorry, something went wrong while calculating dependencies; propably some required packages are masked. You'll have to fix it manually. Please see if you don't yet know how to handle this.\n\n"

echo "Love & Kisses - Your pretend-system-update script") | mail -s "${MAIL_SUBJECT}" "${MAIL_TO}"

Now change the variables until you like them ;)

Next review the permissions set on the file:

jane ~#
chown root:cron /usr/local/bin/pretend-system-update.shImage:CursorOFF.gif
jane ~#
chmod 750 /usr/local/bin/pretend-system-update.shImage:CursorOFF.gif

After that 'ls -l' should look something like this:

Code: Checking permissions of /usr/local/bin/
-rwxr-x--- 1 root cron 827 2007-03-23 02:50 /usr/local/bin/

Add the cronjob

To add a cronjob running the script on a regular basis run 'crontab -e' and append the following line:

jane ~#
crontab -eImage:CursorOFF.gif
Code: Add this to root's crontab
@weekly         /usr/local/bin/ > /dev/null

Note: This runs the script every sunday morning. If you want it to be executed more often or in different schedule please have a look at the gentoo cron guide, and possibly remove the word 'Weekly' from the script's MAIL_SUBJECT variable.


So, now your system will keep you informed about fresh packages :) To see if it works you can invoke the script manually, by typing:

jane ~#

Note: Remember, this won't present you any output; you will receive a mail instead.
Retrieved from ""

Last modified: Sat, 07 Jun 2008 07:59:00 +0000 Hits: 9,707