I find the Ubuntu automated check-for-updates a bit limiting. I want it to check for updates daily, but as it uses a daily crontab to manage this, the PC has to be switched on at the time the cron job is expecting to run. If my usage pattern changes, I can end up going several days without an update check because the PC happens never to be on at the right time.
I could change it to do the check every ten minutes, but that hammers the Canonical servers unnecessarily. What I really want to do is check for updates once per day whenever the PC happens to be switched on.
So I wrote this little script that I put in /usr/bin/apt-update . It simply checks to see whether it has been run already today (by comparing the current date against the modification date of a touch file). If it has been run today, then it doesn’t perform the check. Otherwise, it performs the check, and touches the touch file to prevent further runs.
#!/bin/bash touchfile=/root/.aptlastcheck now=`date +%Y-%m-%d` [[ -e $touchfile ]] && last=`date -r $touchfile +%Y-%m-%d` || last=0 [[ $now != $last ]] && apt-get update touch -d $now $touchfile
I then added a root crontab:
1,11,21,31,41,51 * * * * apt-update
This runs the apt-update script every ten minutes, whenever the PC is on. So I get speedy updates without being nasty to the Canonical servers.


