Pacman email updates notification ·
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/ 

SUBJECT="System update: $HOST@$DOMAIN"

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

if echo $updates_raw | grep "there is nothing to do"
    echo Everything is up to date
    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"

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
*  1  *  *  * root run-parts /etc/cron.daily
[root@arch ~]# crontab -e
  0 1 * * * /etc/cron.daily/ > /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.