Computer Old Farts Forum
 help / color / mirror / Atom feed
From: "Theodore Y. Ts'o" <tytso@mit.edu>
To: Grant Taylor <gtaylor@tnetconsulting.net>
Cc: coff@minnie.tuhs.org
Subject: Re: [COFF] Powershell better than Bourne shell?
Date: Fri, 19 Nov 2021 18:00:16 -0500	[thread overview]
Message-ID: <YZgsgBR5MiMLuiT5@mit.edu> (raw)
In-Reply-To: <39215532-47b8-92ba-ce82-d1307ce5be03@spamtrap.tnetconsulting.net>

On Thu, Nov 18, 2021 at 06:12:12PM -0700, Grant Taylor via COFF wrote:
> I've been told that PowerShell and / or the commands run therefrom actually
> pass structural data that is easy to query /if/ you know how to do so.  It's
> this structure vs free form textual output that is common in Unix shells
> that make the biggest difference.  Think XML markup vs an unstructured text
> file.  (Though you don't actually see the structure scaffolding.)

So I take it you can do something a bit more civilized than this in Powershell?

    run_gcloud compute instances describe --zone "$z" "$i" --format=json > "$inst_info"
    kver=$(jq < "$inst_info" 2> /dev/null
	'.metadata.items[] | select(.key == "kernel_version") | .value' | \
	sed -e 's/^"//' -e 's/"$//' -e 's/^Linux xfstests-[0-9A-Za-z-]* //' \
	-e 's/ .*//')
    gce_status=$(jq < "$inst_info" .status | sed -e 's/^"//' -e 's/"$//')
    status=$(jq < "$inst_info" 2> /dev/null \
        '.metadata.items[] | select(.key == "status") | .value' | \
	sed -e 's/^"//' -e 's/"$//')
    ip=$(jq < "$inst_info" 2> /dev/null \
	'.networkInterfaces[] | .accessConfigs[] | select(.name == "external-nat") | .natIP' | \
        sed -e 's/^"//' -e 's/"$//')
    echo "$i $ip - $kver - $status - $gce_status"

I probably should rewrite the 3500-4000 or so lines of bash script
which is gce-xfstests in Python or Go, but the script has been growing
over the years, and in many ways shell scripting is one of the faster
languages for prototyping new functionality, at least for me, than
Python.  Plus which, bash doesn't do forced march upgrades like Python
does....

					- Ted
_______________________________________________
COFF mailing list
COFF@minnie.tuhs.org
https://minnie.tuhs.org/cgi-bin/mailman/listinfo/coff

  reply	other threads:[~2021-11-19 23:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 23:03 Greg 'groggy' Lehey
2021-11-19  1:12 ` Grant Taylor via COFF
2021-11-19 23:00   ` Theodore Y. Ts'o [this message]
2021-11-20 15:54     ` Michael Kjörling
2021-11-19  5:15 ` Adam Thornton
2021-11-19  6:19   ` Andrew Warkentin
2021-11-19 18:44     ` Steffen Nurpmeso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YZgsgBR5MiMLuiT5@mit.edu \
    --to=tytso@mit.edu \
    --cc=coff@minnie.tuhs.org \
    --cc=gtaylor@tnetconsulting.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).