[ Date Index ]
[ Thread Index ]
[ <= Previous by date /
thread ]
[ Next by date /
thread => ]
[LUG]Re: writing shell scripts
- To: list@xxxxxxxxxxxxx
- Subject: [LUG]Re: writing shell scripts
- From: Simon Avery <digdilem@xxxxxxxxx>
- Date: Fri, 24 Oct 2025 21:02:07 +0100
- Delivered-to: dclug@xxxxxxxxxxxxxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dcglug.org.uk; s=1760519162; h=Content-Type:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Help:List-Id:Subject:Reply-To:To:Message-ID:Date: From:In-Reply-To:References:MIME-Version:Sender:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Archive; bh=taP2ISe3pwxmqQhzUgasaQi6xFmibksFJZXOiNo0jT8=; b=G/6+Yv+83resWg5cpMSsX483JZ k2M/jcMdeJw+AhkAKm85UB0cTkyk/Uhonsa2pRSf1tgu/Uk/bxSLeQL64a3WIOCD3L1otcPUm5g+O hBzt+t6AjghH9nM23DSOkZ7oBDB0B1dwMwA4Co+bKajWx8chMHGUB/B1JrqHtmUIDOTE=;
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761336165; x=1761940965; darn=dcglug.org.uk; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=UmgnvG22WfAy05HRjHO0s5lglhN7IdiTPK032MBY8dk=; b=nFA5dQpVVP7IPFPC/XGoBuDvY4FG2aA2bdJxeJYvdZSRd/n6PhxoVrUJ/iGzD+lnIE VJ8ZUem1KdYONAmWoLmC/SX4HOyl7q7w7QlDXKIKVlMzu0D9miiwni7jWD6w3dNSI2AS yLYwny2XR4lm1comTheASQwqo+s/OtHd6NVTvAOP0bd0S24l2JetINxG4b60hv813EpN M3IZzQVauCm/zr1+1vbrfC5trekIPShrnmAlrujXFPvoqLsMLFiVZITiMlw/hFpurZNb GHHKyo8Ezk1hIHFX+3Pd8ohXIKspMhCWPCNF3MZn8d343ESgVyhmfRUP5LAbujS8uffd Kc5g==
Hi Paul,
A lot of my job involves writing scripts to do stuff, as does any sysadmin. One thing I've learned is that the correct way to do something is whatever way works for you.
Unless you're required to adhere to a particular standard (which isn't unusual), then one of the luxuries we can have is to use our own tools. For me, and this problem, it would be bash. I prefer writing code in perl, but there's a pleasing symmetry in chaining together linux's tools to do some pretty complex things. Things like head, sed, awk, date etc are astonishingly powerful when you start to read their manpages.
Enough philosophy; your outline:
1 Take a text file or list of urls (lets say Code Club Activities)
2 Run the script say, every monday at 02:00 am
3 each time the script is run, it will use the toot (mastodon cli tool) to
4 send that url to a Mastodon account.
5 then the next time it is run, send the next url in the list.
> I think I need to start by identifying the correct way to do this, then
write or get help writing the a script to do this.
For me, that would be something like (not tested)
Scheduling, crontab always;
0 2 * * MON /path/to/your/script.sh
One method in two steps
Read the first line of the text file and pass it to toot as an argument. Then delete the first line so you don't re-send it.
Eg;
---
#!/bin/bash
toot "$(head -n 1 /path/to/file.txt)"
sed -i '1d' /path/to/file.txt
---
(Add whatever arguments you need to toot to specify server and channel and auth if needed)
There are thousands of ways to do this, and the above is a very quick and dirty way.
And Oliver gives very useful advice. AI such as Chatgpt, Claudebot, Gemini et all are very very good at this sort of stuff. I've played around and written entire web apps using gemini within five minutes, using my preferred perl webstack (plack) and it did it in a way that I learned new stuff about plack despite having used it for over a decade.
Or just as a reminder. Eg, sed above, ask it, "bash, how delete first line of a text file". Boom, several answers. Honestly, this year has been a revelation for linux users in the ability of these assistants to genuinely offer good advice on technical aspects. Just... don't give them anything confidential...
--
The Mailing List for the Devon & Cornwall LUG
FAQ: https://www.dcglug.org.uk/faq/