Automatic sync with update and glsa check
The script does the following:
emerge sync
emerge -pvuD world
- check for packages which can be upgraded but aren’t shown by
emerge -pvuD world
- list all glsa vulnerabilities
- email the output of the previous commands (except for the sync output of course).
- download (not install!) all packages needed for
emerge -pvuD world
#!/bin/bash
# The email-address where the output will be sent to.
EMAIL='your@email'
# The subject for the email.
SUBJECT='Maintenance script'
############# START SCRIPT #############
emerge --sync
emerge -uDpvN world > /tmp/maintenance-mail
echo -e "\n" >> /tmp/maintenance-mail
# Find outdated packages which aren't found by 'emerge -pvuD world'
# I've chosen to execute this command once a week because it takes quite some time.
if [ `date +%u` = 7 ]; then
echo -e "All outdated packages: \n" >> /tmp/maintenance-mail
for i in `equery -C -q list | cut -d ' ' -f 5 | sed -n 's/-[0-9]\{1,\}.*$//p'`; do
if (emerge -p $i | grep -q "U \]"); then
echo $i >> /tmp/maintenance-mail
fi
done
echo -e "\n" >> /tmp/maintenance-mail
fi
glsa-check -t all >> /tmp/maintenance-mail
cat /tmp/maintenance-mail | mail -s "$SUBJECT" $EMAIL
rm -f /tmp/maintenance-mail
emerge -ufDN world
exit 0
Change the email, put the script somewhere in /usr/local/sbin
(/usr/local/sbin/maintenance.sh
for example) and change the permissions to make it executable for root:
chmod 700 /usr/local/sbin/maintenance.sh
Add the script to crontab and you’re ready. This crontab line would execute the script once a day at 8 am:
0 8 * * * /usr/local/sbin/maintenance.sh > /dev/null 2>&1
Original post by BoZ: http://forums.gentoo.org/viewtopic-t-545628-start-0.html