/ Sugoi

Sugoi's Storage Counter

If you've been on sugoi then you'll probably notice that it keeps track of how much stuff has been uploaded, and how much total storage it uses.

Stats as of 12:25pm 9/5/2016

I'm not much of a web developer, programmer etc (I'm not at all one), so the way I got that to work was quite weird and I'm not sure if anyone who knows PHP, or anything like that would have done it the way I did because it's so long winded, I sometimes feel like looking for a better way to do it but I actually really like the Rube Goldberg feel to it.

It's all done in a little bash script I pulled together by breaking down what I wanted to do.

Firstly, I have a copy of my index.html page for sugoi, which has the line where the stats are kept blanked, the first portion of the script overwrites index.html with index.html.plc.

cp /var/www/sugoi/index.html.plc /var/www/sugoi/index.html

Next section of that takes the newly copied index.html and adds in the amounts of data stored, using a combination of du, grep, awk and sed, placing it specifically where I ask it using sed.

du -shc /opt/qt | grep total | awk '{print $1 "iB of data stored - split across"}' | sed -i '26r /dev/stdin' /var/www/sugoi/index.html

Next up is the amount of files in the directory where sugoi uploads them to, this time using a combination of ls, grep, awk and sed.

ls /opt/qt -l | grep -v ^l | wc -l | while read line; do echo $line files, values updated every 5 minutes.; done | sed -i '27r /dev/stdin' /var/www/sugoi/index.html

It's not the most intuitive but it is dirty and quick and does exactly what I wanted it to. If you have any better ideas on how to achieve this, by all means let me know.

Whole script located here.