Skip to content

Instantly share code, notes, and snippets.

@Remiii
Created November 21, 2014 14:12
Show Gist options
  • Select an option

  • Save Remiii/3750b63f8a8d76f9ba41 to your computer and use it in GitHub Desktop.

Select an option

Save Remiii/3750b63f8a8d76f9ba41 to your computer and use it in GitHub Desktop.
HW state log

hw-state-log

#!/bin/bash
# HW state log by Remiii
# Package `bc` : (sudo apt-get install bc)
LOG_FILE='hw-state-log.log'
echo `date` >> ${LOG_FILE}
echo CPU: `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`% >> ${LOG_FILE}
FREE_DATA=`free -m | grep Mem` >> ${LOG_FILE}
CURRENT=`echo ${FREE_DATA} | cut -f3 -d' '` >> ${LOG_FILE}
TOTAL=`echo ${FREE_DATA} | cut -f2 -d' '` >> ${LOG_FILE}
echo RAM: $(echo "scale = 2; ${CURRENT}/${TOTAL}*100" | bc)% >> ${LOG_FILE}
echo HDD: `df -lh | awk '{if ($6 == "/") { print $5 }}' | head -1 | cut -d'%' -f1`% >> ${LOG_FILE}
echo '' >> ${LOG_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment