Some time back I wrote a blog on how to get your site stats using curl in bash shell. Today we will use the same script to get the stats every few seconds on the terminal on the same line, similar to progress meter.
Here is the script and the description:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/bin/bash - #=============================================================================== # # FILE: update_stats.sh # # USAGE: ./update_stats.sh # # DESCRIPTION: Update the stats inline in shell every $1 seconds. # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: <a class="zem_slink" title="Amit Agarwal" rel="homepage" href="http://amit-agarwal.co.in">Amit Agarwal</a> (AKA), amit.agarwal@amit-agarwal.co.in # COMPANY: Individual # VERSION: 1.0 # CREATED: 06/21/2010 11:27:16 PM IST # REVISION: --- #=============================================================================== sleep_time=30 #the time to wait between stats collection run_stats=get_stats # the script to run to get the stats filename=/tmp/statpress.html # the filename where the script is storing the html file of your statpress page. eval $run_stats 2><a class="zem_slink freebase/en/dev_null" title="/dev/null" rel="wikipedia" href="http://en.wikipedia.org/wiki//dev/null">/dev/null</a> while (true) do <!--loginview start-->values=$(cat $filename | w3m -dump -T <a class="zem_slink freebase/en/html" title="HTML" rel="wikipedia" href="http://en.wikipedia.org/wiki/HTML">text/html</a> |<a class="zem_slink freebase/en/grep" title="Grep" rel="wikipedia" href="http://en.wikipedia.org/wiki/Grep">grep</a> "^Visitor\\|^Pageviews"|<a class="zem_slink freebase/en/awk" title="AWK" rel="homepage" href="http://cm.bell-labs.com/cm/cs/awkbook/index.html">awk</a> \'{print $10}\'|tr "\\n" " ") time=$(date) printf "$time --> $values \\r"<!--loginview end--> sleep $sleep_time done |
Related articles by Zemanta
- for loop in bash script on solaris without seq (amit-agarwal.co.in)
- Get the mappings from tex file for vim plugins (amit-agarwal.co.in)
- unbound variable – bash completion not working and having issues with other stuff like command not found. (amit-agarwal.co.in)
- bash builtins (almirkaric.com)
Hey! Just wanted to thank you for the informative post! Do you post every week? 🙂 Thanks!
test test test test
It was very interesting for me to read the article. Thanks for it. I like such topics and everything connected to this matter. I would like to read a bit more soon. BTW, pretty good design this site has, but what do you think about changing it from time to time?
Kate Kripke