Skip to content

Instantly share code, notes, and snippets.

@cjsewell
Created August 27, 2017 20:15
Show Gist options
  • Save cjsewell/a44d4ab9e2b5bc60244c78c4e010d3bf to your computer and use it in GitHub Desktop.
Save cjsewell/a44d4ab9e2b5bc60244c78c4e010d3bf to your computer and use it in GitHub Desktop.
#!/bin/bash
HIGH=0.2;
LOG_FILE=/var/log/highload.log;
CURRENT_LOAD=$( uptime | awk -F'load average:' '{ print $2 }' | awk -F',' '{gsub(/[ \t]+/, "", $1); print $1}' );
IS_HIGH=$( echo "$CURRENT_LOAD >= $HIGH" | bc );
if [ $IS_HIGH -eq 1 ] ; then
top -b -n 1 2>&1 | while read line; do echo -e `/bin/date` "$line"; done >> $LOG_FILE
fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment