Pacman email updates notification · uwot.eu
another meaningless subtitle

Pacman email updates notification

· by fabio · Read in about 1 min · (211 Words)
cron email notification pacman script updates

Pacman as long as I know does not provide any method for sending an email notification when there are updates available.
SSH into the Arch box just to find out if there are updates available is really annoying so I wrote a simple bash script to do the dirty work on my behalf.

[root@arch ~]# cat /etc/cron.daily/check4updates.sh 
#!/bin/bash

HOST=hostname
DOMAIN=domain
SUBJECT="System update: $HOST@$DOMAIN"
EMAIL_ADDR="name@domain"

### Query pacman for available updates
updates_raw=$(pacman -Syu <<< n)

if echo $updates_raw | grep "there is nothing to do"
then
    echo Everything is up to date
else
    updates=${updates_raw#*Packages ([1-9])}

    ### extract packages update list
    up_raw=${updates%Total Download*}
    up=$(echo $up_raw | tr ' ' '\n')
    #echo -e "$up" > report.txt

    ### extract update size
    us=${updates#*Total Download*}
    #echo -e "\nTotal Download $us" >> report.txt

    ### compose email
    email_text="New updates available for host $HOST\n\n$up\n\nTotal Download$us"
    echo -e "$email_text" | mail -s "$SUBJECT" "$EMAIL_ADDR"
fi

To schedule the cron job to run everyday at 1 am edit the following files:

[root@arch ~]# cat /etc/cron.d/0daily 
# Run the daily jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
*  1  *  *  * root run-parts /etc/cron.daily
[root@arch ~]# crontab -e
  0 1 * * * /etc/cron.daily/check4updates.sh > /dev/null 2>&1

The script works exactly like yum-cron does: if there are updates available and email is being sent, else it does nothing.