We’re six years later, and I still haven’t gotten around to any kind of “Tinkering With The Raspberry Pi“. That does not mean that I still have to write down the production numbers from our solar panels by hand, however. The Asus eeePC, running Xubuntu and a bit of software a former colleague of mine and I hacked together, takes care of that. In doing so, it constructs a number of text files: one for each day, listing the current production in Wh every ten minutes, and one for each year, detailing the total production for each day. The backup of these files is made every day by a tool called ‘grive2‘ (but I’ll write about that later).
The setup works fine, almost all the time. But somehow the SMA Sunny Boy gets confused and creates ‘yearly’ files for years other than the current calendar year. Those files are utterly useless and clutter the hard disk as well as the backup, so I decided to get rid of them automatically. To prepare for the first days of a new year, the script should also be able to leave the file for the previous year in place – there may be two valid ‘yearly’ files in January, should I fail to archive the old year on New Year’s eve or on Jan. 1st.
To exercise my *nix shell skills, I decided to do that in ‘bash‘ rather than extend the current Python tools.
As is my habit, I decided to start with a demo script that does what I want on dummy data. For demo purposes the JDoodle website is a great resource, at least for ‘bash’ scripting (I did not try any of the 67 other languages available on the site). This allowed me to work on the code on my Mac-with-big-screen, and take the necessary screenshots for this post.
Here is the code I came up with:

Click on the image to get it in the form of a PDF file,
ready for copy/paste operations.
Nothing spectacular, as shown by the output. Now all I have to do is turn this into a little non-demo script and add it my crontab on the eeePC… Come and see in six years or so ;-)

PS. I’m just dabbling in bash scripting, so if there are better solutions for my problem, don’t hesitate to explain them to me, please.
Read Full Post »
You must be logged in to post a comment.