trackthis - STDIN to graph

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

trackthis - STDIN to graph

Unread post by machinebacon » Fri May 08, 2015 12:31 pm

throw a value at it, and it will be printed out as graph

usage: trackthis VALUE (OUTPUT_FILE)

Code: Select all

#!/bin/bash
# tracks anything you throw at it
# scale is 1:6

horizontal=$1
scaled=6

if [[ $2 == "" ]]; then
	trackfile=/tmp/trackfile
else
	trackfile=$2
fi

graph(){
	for i in `seq $1`
	do
	if [ `expr $i % $scaled` -eq 0 ]
	then
		echo -n "="
	fi
	done
	echo " $horizontal"
}

printgraph(){
	for line in ${horizontal[@]}
	do
	etad=$(date +%H:%M:%S)
	(printf "$etad:  " 2>&1) | tee -a $trackfile
	(graph $horizontal 2>&1) | tee -a $trackfile
	done
}

while :
do
	read -a horizontal
	printgraph
	exit 0
done
Example:

Code: Select all

user@grill:~$ while true; do free -m |grep cache|tail -n1|awk '{ print $3 }' | trackthis; sleep 2s; done
19:29:08:  ============================================ 268
19:29:10:  ============================================ 268
19:29:12:  ============================================ 268
..gnutella..

Post Reply