notification snippets

Kill Mac OS disk warning notification

Tagged kill, notification, osx, disk, disk space  Languages bash

This explains how you can kill the Mac OS disk warning notification that reminds you that you need to buy more overpriced hardware with more disk space from Apple even if you have plenty of disk space left on your brand new Apple crippleware computer.

Before Mac OS Mojave this used to work:

# 1 = 1Gb
$ defaults write com.apple.diskspaced minFreeSpace 1
$ killall diskspaced

Setting minFreeSpace to 1 prevents the notification from showing up every second, if free disk space is above 1 Gb.

With Mojave we have to completely disable the agent:

$ launchctl unload -w /System/Library/LaunchAgents/com.apple.diskspaced.plist

Tested on Mac OS Mojave and iMac crippleware.

See:

https://apple.stackexchange.com/questions/254485/silencing-your-disk-is-almost-full-notification

https://apple.stackexchange.com/questions/345120/silencing-your-disk-is-almost-full-notification

Notifications for failing cron jobs

Tagged cron, failure, notification, slack  Languages bash

Here’s a simple way of receiving a notification to a Slack channel when a cron job fails:

#!/usr/bin/env sh

# Replace this with the command
echo "hello world" &> /var/log/app.log

if [ $? -eq 0 ]
then
  curl -X POST -H 'Content-Type: application/json' --data "{\"text\":\"Cron job ran successfully $(tail -n 5 /var/log/app.log)\"}" $SLACK_URL
  exit 0
else
  curl -X POST -H 'Content-Type: application/json' --data "{\"text\":\"Cron job failed $(tail -n 5 /var/log/app.log)\"}" $SLACK_URL
  exit 1
fi

Set the SLACK_URL environment variable to your slack channel’s hook URL.

A message will be sent to the Slack channel whenever the command fails along with the last 5 lines from the log file.