Created
December 5, 2017 17:40
-
-
Save jhyland87/5f11b47ddedcb0005b020029f82c35cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
function trim { | |
if test -p /dev/stdin; then | |
data="$(</dev/stdin)" | |
elif test -n "${1}"; then | |
data="$*" | |
else | |
return 1 | |
fi | |
echo "${data}" | sed -E -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' | |
} | |
declare -A settings | |
settings['ff_sessionstore']="/home/guest/.mozilla/firefox/*.default/sessionstore.js" | |
settings['out_fmt']="%-25s %s\n" | |
declare -A data | |
data['ff_windows']=$(cat ${settings['ff_sessionstore']} | python -c 'import sys,json;data=json.loads(sys.stdin.read()); print len(data["windows"])') | |
data['ff_tabs']=$(cat ${settings['ff_sessionstore']} | python -c 'import sys,json;data=json.loads(sys.stdin.read()); print sum(len(t) for w in data["windows"] for t in w["tabs"])/4') | |
data['uptime_seconds']=$(cut -d ' ' -f1 /proc/uptime) | |
data['uptime_idle']=$(cut -d ' ' -f2 /proc/uptime) | |
data['uptime_display']=$(uptime | cut -d ',' -f 1 | trim) | |
data['load_average']=$(uptime | cut -d ':' -f4 | trim) | |
data['load_average_5min']=$(echo ${data['load_average']} | awk -F', ' '{print $1}') | |
data['load_average_10min']=$(echo ${data['load_average']} | awk -F', ' '{print $2}') | |
data['load_average_15min']=$(echo ${data['load_average']} | awk -F', ' '{print $3}') | |
data['mem_total']=$(free | grep -E '^Mem' | awk '{print $2}') | |
data['mem_used']=$(free | grep -E '^Mem' | awk '{print $3}') | |
data['mem_free']=$(free | grep -E '^Mem' | awk '{print $4}') | |
printf "${settings['out_fmt']}" "FireFox Windows" "${data['ff_windows']}" | |
printf "${settings['out_fmt']}" "FireFox Tabs" "${data['ff_tabs']}" | |
printf "${settings['out_fmt']}" "Uptime" "${data['uptime_display']}" | |
printf "${settings['out_fmt']}" "Uptime (seconds)" "${data['uptime_seconds']}" | |
printf "${settings['out_fmt']}" "Load Average (5 min)" "${data['load_average_5min']}" | |
printf "${settings['out_fmt']}" "Load Average (10 min)" "${data['load_average_10min']}" | |
printf "${settings['out_fmt']}" "Load Average (15 min)" "${data['load_average_15min']}" | |
printf "${settings['out_fmt']}" "Memory Total" "${data['mem_total']}" | |
printf "${settings['out_fmt']}" "Memory Used" "${data['mem_used']}" | |
printf "${settings['out_fmt']}" "Memory Free" "${data['mem_free']}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment