Happiness and Misadventures

Bashing the Weekend

Last weekend was so rainy and empty that I decided to start writing a Bash script. The need was simple: I wanted an easy way to post on the social networks my latest blog post. I couldn't find anything similar on the web, quick and easy. I had already saved the XML file of this very blog on my laptop a few days ago, when I got the idea. So, what better motivation that rainy days?

I could have used fancy languages as Python, but the fact is I love Bash. It's simple1, and so powerful. The sed and awk combo2 solves half of the issues a system admin will have in years. So, after downloading the RSS with wget, the complicated part came: parsing the XML.

Long story short: Python would have been an easier choice.

But I didn't care, and played it simple: why bother parsing all the <title> tags when you only need the second one? The first is the blog title, and the second one is the last post – at least, with the handful of websites I've tested.

Then, after a little sed magic to get the Publish Date of the given post, I wanted to facilitate the posting on Mastodon using the beautiful toot. At first, I got an error on my instance, but then I tried on another one which runs an older version, and everything worked… So I integrated toot, along with the possibility to post with various visibility options.

Then, there was another little learning step I had avoided until today because I didn't need it: getopts to get the multiple parameters managed in a correct way. Well, that was better than I expected!

And finally… I published it on Gitea, in case anyone will need something similar. I added some comments to make it more comprehensible, but it is quite straight-forward.

Screenshot of the output of the script
There it is, made with https://carbon.now.sh/ + https://squoosh.app/

🎮 Really enjoying Dave the Diver!

🎧 Italian pride: Ufomammut

📖 Halfway through the Damnable Tales - wonderful!

  1. Not, it's NOT. But I use it on a daily basis, and I want to master it… one day.

  2. To be honest, I will add StackOverflow to the cocktail.

#fediverse #open source