Skip to content

Instantly share code, notes, and snippets.

@fcamel
Last active December 18, 2015 15:19
Show Gist options
  • Save fcamel/5803932 to your computer and use it in GitHub Desktop.
Save fcamel/5803932 to your computer and use it in GitHub Desktop.
#!/bin/bash
OUT="/tmp/htop.out"
/bin/bash -c "sleep 1; killall htop" &
htop > $OUT
# Ref. Remove color codes (special characters) with sed
# http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
result=$(sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" $OUT | sed 's/.*Mem.*[^0-9]\([0-9]\+\/[0-9]\+\)MB.*Swp.*/\1\n/')
time=$(date)
echo -e "$time\t$result MB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment