-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Earlier in the day on the z/VM list, I asked for a bit of help writing a
pipeline to return those guests attached to both a vswitch and listening
to signal shutdown. This is from hints taken from the determine which
guests are running linux thread.
What I ended up with was this nice, succinct little script:
/* */
VSWITCH=VSWG
'PIPE ( endchar ?) ',
'cp query signals shutdown | drop 2 | specs word 1 1 ',
' | a: lookup master | sort | literal Linux Guests | cons',
'? cp query vswitch ' VSWITCH ' active ',
' | locate /Adapter Owner:/ | specs word 3 1 | a:'
Those of you who are pipe mistresses/masters will have to forgive my
halting stumblings, but nonetheless some might find it useful as is.
More interesting, though, I caught a bug this afternoon, and just to see
if it could be done, I attempted to write a pipelines alike
implementation of the same thing in bash shell script on a suitably
privileged linux guest. I post that here also so all can marvel at the
donkey in a wig.
#!/bin/bash
# Demo how a CMS pipeline alike multi stage input/output splitting and
# joining can be accomplished in bash.
#
# See which vm guests are both listening to signal shutdown, and
# attached to a specific vswitch.
#
# Please take this for what it's worth, a simpleminded demo of how
# something could be done, rather than anything useful
# Pretty much have to predeclare my input/output streams, which are
# accomplished using named pipes /tmp/fifoX.<pid>
# For this script, use labels of the form "fX"
vswitch=vswg
f1=/tmp/$( basename $0 ).fifo1.$$
mkfifo $f1
# Cleanup fifo on exit
trap "rm $f1 2>/dev/null" INT TERM EXIT
# An extremely simpleminded LOOKUP DETAILS
# STDIN should have master records, one per line
# $1 (first arg) is the file descriptor no for the detail
# records inputs
simplelookup() {
masters=$(
while read word ; do
echo "$word"
done)
masters=$( echo -n $masters | sed -e 's/ /|/g' )
# echo "scanning for masters ($masters) on detail input fd $1"
egrep "($masters)" <&${1}
}
# Stage one
vmcp query signals shutdown | awk 'FNR > 2 {print $1}' | \
simplelookup 3 3<$f1 | sort &
# Stage two
vmcp -b 65536 query vswitch $vswitch active | \
awk '/Adapter Owner:/ {print $3}' >$f1 &
# end of script, make sure to wait for everything to complete before
# exiting.
wait
My commentary: I recall from past discussions comparing and explaining
CMS pipelines that one of it's core features said to be missing in Unix
pipelines was multi-stage pipelines. This experiment was mostly just to
see if the whole multi-stage input/output, splitting and joining i/o
streams was first feasible, and if so, not insanely hard.
Specifically I find the bash i/o redirection and fifo use was easy
enough for me to grok, giving at least the base of a pipe like i/o stage
capability. Also, many of the standard unix tools (awk, cut, sed, grep,
tail, head) are very useful and make duping many of the pipe commands
straightforward.
On the flip side, CMS pipelines still has functions not easily replaced
in Unix, (I obviously had to cobble up a replacement for LOOKUP in my
script), and even if there were easy replacements for all commands this
script is still more verbose than the CMS pipe I started with, even
after removing comments and the like.
For myself, I'm coming at this as a long time unixer only recently
working with CMS pipelines. As such, I find thinking in pipes to be
foreign.
E.g., when I tried to do several other tasks, e.g. produce a list of
processes belonging to currently logged in interactive users, of the
form 'username procname full_user_info', that would combine input from
three sources, 'ps -ef', 'getent passwd', and 'who' - I found it hard to
arrange three such pipes in my head.
However, if you're native to this mode of thought and find it easier to
do than 'standard' unix scripting, perhaps knowing that you can do this
will allow a few more options for you.
At that, I'll leave you all draw your own conclusions, and sit back with
my toasting marshmallows a ready!
Thanks,
- -- Pat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkqE37oACgkQNObCqA8uBsy9BwCeLvOo3LZKGFb93TZN0hOyZ5zj
aqAAn2UC+lBJ3ICQtdwG58Aks/pbXAb6
=9Pon
-----END PGP SIGNATURE-----
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390