Giter Site home page Giter Site logo

slack-notify-apt-upgrade's Introduction

slack-notify-apt-upgrade

Bash script to notify available apt upgrades via slack.

How it works

The bash script simply retrieve new lists of packages via apt-get update and then calls apt-get upgrade --simulate to check for available upgrades.

If the result of the simulation looks like

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

we are done. If there would be more than "0 upgraded" packages, we'll send the Slack notification.

Note: You need to be root on your server because apt-get update must run as root.

Installation

  1. Save slack-notify-apt-upgrade.sh to your server, for example within /root/scripts/

  2. chmod u+x slack-notify-apt-upgrade.sh

  3. Create an incoming webhook for Slack (see https://api.slack.com/incoming-webhooks)

  4. Open the script with your editor and update the configuration section:

    • your Slack webhook url
    • the slack channel to which the notification should be sent to
    • (optional) a username
  5. As root user edit your cronjobs with crontab -e and add a line like this to call the script twice a day:

    0 6,20 * * * /root/scripts/slack-notify-apt-upgrade.sh > /dev/null 2>&1

That's it.

Running it from cron.daily

Remeber to rename it and remove the .sh extension The cronjobs in /etc/cron.hourly (and the other, similar directories) are executed by run-parts. run-parts is a little picky about filenames. By default it doesn't execute files whose filenames contain anything other than (all of those from ASCII)

uppercase letters lowercase letters digits underscores dashes ("minus signs") So if your script has a filename of for example "myscript.sh", it just is ignored, because run-parts does not like the dot. https://askubuntu.com/questions/611336/why-putting-a-script-in-etc-cron-hourly-is-not-working

Imaginable Extensions

  • Modify the color attribute of the Slack message due to the existence of security related upgrades (at the moment it's always "danger").
  • Cache the result of the simulation in a file to avoid resending the identical message over and over.
  • ...

slack-notify-apt-upgrade's People

Contributors

billygr avatar zippex avatar

Stargazers

Tobias Farrenkopf avatar

Watchers

James Cloos avatar

Forkers

shawn-ogg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.