From 07fc2644a237187dd4c5680e88f4adadbf533603 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Wed, 12 Aug 2015 12:06:23 -0600 Subject: Initial commit of the working files --- segments/ifstat.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 segments/ifstat.sh (limited to 'segments/ifstat.sh') diff --git a/segments/ifstat.sh b/segments/ifstat.sh new file mode 100755 index 0000000..2666496 --- /dev/null +++ b/segments/ifstat.sh @@ -0,0 +1,39 @@ +# Show network statistics for all active interfaces found. + +run_segment() { + type ifstat >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + return 1 + fi + + sed="sed" + type gsed >/dev/null 2>&1 + if [ "$?" -eq 0 ]; then + sed="gsed" + fi + + data=$(ifstat -z -S -q 1 1) + interfaces=$(echo -e "${data}" | head -n 1) + flow_data=$(echo -e "${data}" | tail -n 1 | ${sed} "s/\s\{1,\}/,/g") + index=1 + for inf in ${interfaces}; do + type="" + case ${inf} in + eth*) type="⎆" + ;; + wlan*) type="☫" + ;; + en*) type=" " + ;; + esac + if [ -n "${type}" ]; then + formate=$(echo "${formate} ${type} ⇊ %.2f ⇈ %.2f") + holder=$(echo "${holder},\$$((index)),\$$((index+1))") + fi + index=$((index+2)) + done + if [ -n "${formate}" ]; then + echo $(echo "${flow_data#,}" | awk -F"," "{printf(\"${formate}\"${holder})}") + fi + return 0 +} -- cgit v1.2.3