JustStarted
JustStarted

Reputation: 75

How to create a graph using shell script

I am writing data in a text file as below by running a script. This data is updated every second.

eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 12 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 20 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 15 Kb/s | Received Bytes: 4 Kb/s | Sent Packets: 33 Pkts/s | Received Packets: 25 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 19 Pkts/s | Received Packets: 12 Pkts/s

I want to make a graph of the # of bytes sent and the # of bytes received. Same for packets.

Upvotes: 0

Views: 6497

Answers (1)

nwk
nwk

Reputation: 4050

You can use https://github.com/holman/spark to create a graph with just shell script (although it only works with bash and not POSIX sh). You can watch it update in real time with watch.

graph.sh

!/bin/sh
field=1
tail "$1" | cut -d '|' -f $field | sed -e 's!.*: \([0-9]\+\) .*!\1!' | ./spark/spark

Interactive console

git clone https://github.com/holman/spark
your-process > logfile &
watch sh graph.sh logfile

Output

Every 2.0s: sh graph.sh logfile          Fri Dec 19 22:22:04 2014

▁▁▁█▁

Upvotes: 4

Related Questions