Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created August 19, 2020 10:18
Show Gist options
  • Save eriknelson/b1a0a23ee746c38ce127c9fed5c26f4f to your computer and use it in GitHub Desktop.
Save eriknelson/b1a0a23ee746c38ce127c9fed5c26f4f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# vim: set ft=bash:
update_lc=$(journalctl --since "yesterday" -t yum | tail -n +2 | wc -l)
if [[ $update_lc -gt 0 ]]; then
datestamp=$(date +%s)
scratch_file="{{ scratch_path }}/update-alert-${datestamp}.txt"
journalctl --since "yesterday" -t yum &> $scratch_file
grep -i kernel $scratch_file
restart_required=$?
if [[ $restart_required -eq 0 ]]; then
mail -Ssendwait -s "[Yum Updates Installed: RESTART]" \
-r "{{ mg_smtp_username }}" "{{ mail_to }}" < $scratch_file
else
mail -Ssendwait -s "[Yum Updates Installed]" \
-r "{{ mg_smtp_username }}" "{{ mail_to }}" < $scratch_file
fi
rm $scratch_file
else
echo "FIN" | mail -Ssendwait -s "[No Updates Installed]" \
-r "{{ mg_smtp_username }}" "{{ mail_to }}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment