💾 Archived View for spool-five.com › gemlog › 2021-02-22-first_script.gmi captured on 2023-09-28 at 15:48:48. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-03-01)

-=-=-=-=-=-=-

First Shell Script

After only a month of exploring Gemini, it's already leading me, happily, outside my comfort zone.

This evening I finally sat down to learn a (tiny) bit of sed, in order to create a script that would update a 'quote of the day' section on my homepage.

It's a very simple task, but I'm happy that I got it working without too much effort. I'm sure it's incredibly inefficient. But it works! (or seems to, at least).

If anyone comes across this, maybe they'll point me in the direction of a better solution:

#!/bin/sh

# Pull a random quote from a quotes file and insert it
sort -R ~/path/to/quotes.txt | head -n1 >> /path/to/index.gmi &&

# Delete current quote
sed -i '/^>/d' /path/to/index.gmi &&

# Add quote 'tag' to new quote
sed -i '$s/^/>/' /path/to/index.gmi &&

rsync -aP -e /path/to/index.gmi user@server:/home/gemini/gemini/index.gmi

However, I've still not managed to get it fully automated with cron, since the rsync command requires a ssh passphrase to execute. Will have to figure this out another time.

For now, I'm just happy that gemini-space has encouraged me to expand my horizons a little :)

Edit

Thanks to a suggestion by kelbot, I was able to easily set up the cron job by adding a passwordless ssh key :) Gemini people are great!

kelbot's capsule

Gemlog