Created
July 2, 2012 22:49
-
-
Save ganglio/3036215 to your computer and use it in GitHub Desktop.
BASH: NetSpark IO Geeklet
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/bash | |
INTF=en0 | |
MAXPOINTS=30 | |
echo $1; | |
if [ "$1" == "RESET" ]; then | |
defaults write netspark in "" | |
defaults write netspark out "" | |
defaults write netspark lastIn 0 | |
defaults write netspark lastOut 0 | |
defaults read netspark | |
echo "Reset complete"; | |
exit | |
fi | |
Z0i=`defaults read netspark in` | |
Z0o=`defaults read netspark out` | |
lastIn=`defaults read netspark lastIn` | |
lastOut=`defaults read netspark lastOut` | |
S=(`/usr/sbin/netstat -ib | awk "/$INTF/"'{print $7" "$10; exit}'`) | |
normIn=`echo ${S[0]}-$lastIn | bc`; | |
normOut=`echo ${S[1]}-$lastOut | bc`; | |
cnt=0 | |
for i in $Z0i ; | |
do | |
let cnt=$cnt+1; | |
done | |
if [ "$cnt" -lt "$MAXPOINTS" ]; then | |
Z0i=`echo $Z0i $normIn` | |
Z0o=`echo $Z0o $normOut` | |
else | |
Z1i=`echo $Z0i | sed "s/[0-9]*\ //"` | |
Z1o=`echo $Z0o | sed "s/[0-9]*\ //"` | |
Z0i=`echo $Z1i $normIn` | |
Z0o=`echo $Z1o $normOut` | |
fi | |
defaults write netspark in "$Z0i" | |
defaults write netspark out "$Z0o" | |
defaults write netspark lastIn "${S[0]}" | |
defaults write netspark lastOut "${S[1]}" | |
echo "In : `printf '%7d' $normIn` `/usr/local/bin/spark $Z0i`" | |
echo "Out: `printf '%7d' $normOut` `/usr/local/bin/spark $Z0o`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment