View previous topic :: View next topic |
Author |
Message |
BoZ Tux's lil' helper
Joined: 27 Aug 2003 Posts: 114 Location: The Netherlands
|
Posted: Thu Mar 08, 2007 11:01 pm Post subject: [Script] Automatic sync with update and glsa check |
|
|
I've made a script to daily sync my server and mail a short summary to myself. This way you're always up-to-date and you don't have to login daily to check for any updates available. Since I didn't see any similar script in this forum I thought I might as well post it here.
The script does the following:
1) emerge sync
2) emerge -pvuD world
3) check for packages which can be upgraded but aren't shown by 'emerge -pvuD world'
4) list all glsa vulnerabilities
5) email the output of the previous commands (except for the sync output of course).
6) download (not emerge!) all packages needed for 'emerge -pvuD world'
Because the third action takes some time I've chosen to execute it only once a week.
Here's the script:
Code: | #!/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 -pvuD 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 -fuD 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:
Code: | 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:
Code: | 0 8 * * * /usr/local/sbin/onderhoud.sh > /dev/null 2>&1 |
Special thanks to this script to replace the deprecated qpkg -I.
Any comments and suggestions are welcome. Enjoy! |
|
Back to top |
|
|
Dralnu Veteran
Joined: 24 May 2006 Posts: 1919
|
Posted: Mon Mar 12, 2007 6:06 pm Post subject: |
|
|
I'd suggest running another part to see if there were any changes in USE flags that affect the system and notify the user of such.
Simply adding in
Code: | emerge -pvN world >> /path/to/log |
and appending it to the mail would be nice.
Also, change the mail command to a variable to make things a bit easier to configure. _________________ The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|