Skip to content

Instantly share code, notes, and snippets.

@jcsalterego
Created September 8, 2011 20:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcsalterego/1204570 to your computer and use it in GitHub Desktop.
Save jcsalterego/1204570 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Throw this in your crontab.
#
# https://twitter.com/#!/manton/status/111893189971017729
#
BOSS=boss@example.org
CPU_THRESHOLD=1500
kill_xcode_and_email () {
kill -9 $(ps aux | grep /[X]code | awk '{print $2}');
if [ -n "$BOSS" ]; then
echo "I'm taking the rest of the day off." \
| mail -s "Because of XCode..." $BOSS;
fi
}
xcodeline=$(ps aux | grep /[X]code)
if [ -n "$xcodeline" ]; then
cpu=$(echo $xcodeline | awk '{print $3}' | sed -e 's/\..*//g')
if [ "$cpu" -gt $CPU_THRESHOLD ]; then
kill_xcode_and_email
exit 0
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment