Re: Bash loop failing

2017-05-05 Thread Ted Rodriguez-Bell
If I could make a small suggestion, if you don't need the indices you may find 
loops easier to read without them:

FILE=($(ls))
for F in ${FILE[@]}
do
echo "$F"
done

I'll give out the caution that if you use "set -u" in your scripts (and you 
should!), there can be some really, um, interesting interactions between that 
and ${FILE[@]}. In an empty directory the above with -u throws an error in 
bash, but not in ksh. Using the indices as Neale does is safe in bash even when 
FILE is empty.

Ted Rodriguez-Bell
te...@wellsfargo.com, 415-222-4516
z/VM and Linux on IBM z Systems
Mainframe/Midrange Services (MMS), Enterprise Technology Infrastructure (ETI)


On Thu, 2017-05-04 at 14:40 +, Neale Ferguson wrote:

Rather than using read can you load the results of the command into an array 
and iterate:


FILES=`ls`

FILE=(${FILES})

for ((i=0; i<${#FILE[@]}; i++))

do

   echo ${i} ${FILE[$i]}

   done

Exit


This should load the variables before the other scripts are invoked.


Neale

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the 
message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/



Re: Bash loop failing

2017-05-04 Thread Scott Rohling
I've seen 3 posts from you so they are getting through..   If Michael was
using visual bash they might have been helpful ...   ;-)

Scott Rohling

On Thu, May 4, 2017 at 8:05 AM, Paul Flint <fl...@flint.com> wrote:

> Dear Neale,
>
> I believe you are on to something here.  I have used the BASH string
> arrays and they really rock.
>
> As you likely know, I shall be giving a presentation on something I call
> "Visual Bash", At the VM Workshop next month.  Visual Bash is a framework
> to help make bash programs easier to manage.
>
> Consequently, my interest is not merely academic, I am really interested
> in bash code under zLinux.
>
> Right now the most difficult thing I am grappling with is the Marist
> listserver does not like me.  I am testing this messasge to see if it gets
> through.
>
> Regards,
>
> Flint
>
> On Thu, 4 May 2017, Neale Ferguson wrote:
>
> Date: Thu, 4 May 2017 14:40:42 +
>> From: Neale Ferguson <ne...@sinenomine.net>
>> Reply-To: Linux on 390 Port <LINUX-390@VM.MARIST.EDU>
>> To: LINUX-390@VM.MARIST.EDU
>> Subject: Re: Bash loop failing
>>
>>
>> Rather than using read can you load the results of the command into an
>> array and iterate:
>>
>>
>> FILES=`ls`
>>
>> FILE=(${FILES})
>>
>> for ((i=0; i<${#FILE[@]}; i++))
>>
>> do
>>
>>   echo ${i} ${FILE[$i]}
>>
>>   done
>>
>> Exit
>>
>>
>> This should load the variables before the other scripts are invoked.
>>
>>
>> Neale
>>
>> --
>> For LINUX-390 subscribe / signoff / archive access instructions,
>> send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or
>> visit
>> http://www.marist.edu/htbin/wlvindex?LINUX-390
>> --
>> For more information on Linux on System z, visit
>> http://wiki.linuxvm.org/
>>
>>
> --
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or
> visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
> --
> For more information on Linux on System z, visit
> http://wiki.linuxvm.org/
>

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Paul Flint

Michael,

Glad you got it fixed!

Regards,

Flint

On Thu, 4 May 2017, Michael MacIsaac wrote:


Date: Thu, 4 May 2017 11:12:30 -0400
From: Michael MacIsaac <mike99...@gmail.com>
Reply-To: Linux on 390 Port <LINUX-390@VM.MARIST.EDU>
To: LINUX-390@VM.MARIST.EDU
Subject: Re: Bash loop failing

Thanks to all who replied - I tried most, but not all suggestions

The good news is I got the bug fixed.

It's pretty clear that 'stdin' was getting 'drained' somewhere down the
stack (I'm still now sure where), as John M. suggested.

Using another file descriptor instead of stdin (0) worked around the issue:

 *exec 3<&0  *  # Link file descriptor #3 with
stdin.
 local nextLine
 while read -u 3 nextLine; do
   zVerbose "calling zSetOneSystem $nextLine"
   zSetOneSystem $nextLine
 done *3<* <(echo "$expList")   # read from expList on file
descriptor 3


On Thu, May 4, 2017 at 10:40 AM, Neale Ferguson <ne...@sinenomine.net>
wrote:


Rather than using read can you load the results of the command into an
array and iterate:


FILES=`ls`

FILE=(${FILES})

for ((i=0; i<${#FILE[@]}; i++))

do

   echo ${i} ${FILE[$i]}

   done

Exit


This should load the variables before the other scripts are invoked.


Neale

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or
visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/





--
-Mike MacIsaac

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/



Kindest Regards,



☮ Paul Flint
(802) 479-2360 Home
(802) 595-9365 Cell

/
Based upon email reliability concerns,
please send an acknowledgement in response to this note.

Paul Flint
17 Averill Street
Barre, VT
05641

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Harold Grovesteen
Can you point to more information about Visual Bash?  For those not
attending the workshop, will you be able to share the presentation?

Harold Grovesteen


On Thu, 2017-05-04 at 11:05 -0400, Paul Flint wrote:

> As you likely know, I shall be giving a presentation on something I call
> "Visual Bash", At the VM Workshop next month.  Visual Bash is a framework
> to help make bash programs easier to manage.

>
> Flint

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Michael MacIsaac
Thanks to all who replied - I tried most, but not all suggestions

The good news is I got the bug fixed.

It's pretty clear that 'stdin' was getting 'drained' somewhere down the
stack (I'm still now sure where), as John M. suggested.

Using another file descriptor instead of stdin (0) worked around the issue:

  *exec 3<&0  *  # Link file descriptor #3 with
stdin.
  local nextLine
  while read -u 3 nextLine; do
zVerbose "calling zSetOneSystem $nextLine"
zSetOneSystem $nextLine
  done *3<* <(echo "$expList")   # read from expList on file
descriptor 3


On Thu, May 4, 2017 at 10:40 AM, Neale Ferguson 
wrote:

> Rather than using read can you load the results of the command into an
> array and iterate:
>
>
> FILES=`ls`
>
> FILE=(${FILES})
>
> for ((i=0; i<${#FILE[@]}; i++))
>
> do
>
>echo ${i} ${FILE[$i]}
>
>done
>
> Exit
>
>
> This should load the variables before the other scripts are invoked.
>
>
> Neale
>
> --
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or
> visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
> --
> For more information on Linux on System z, visit
> http://wiki.linuxvm.org/
>



--
 -Mike MacIsaac

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Paul Flint

Dear Neale,

I believe you are on to something here.  I have used the BASH string
arrays and they really rock.

As you likely know, I shall be giving a presentation on something I call
"Visual Bash", At the VM Workshop next month.  Visual Bash is a framework
to help make bash programs easier to manage.

Consequently, my interest is not merely academic, I am really interested
in bash code under zLinux.

Right now the most difficult thing I am grappling with is the Marist
listserver does not like me.  I am testing this messasge to see if it gets
through.

Regards,

Flint

On Thu, 4 May 2017, Neale Ferguson wrote:


Date: Thu, 4 May 2017 14:40:42 +
From: Neale Ferguson <ne...@sinenomine.net>
Reply-To: Linux on 390 Port <LINUX-390@VM.MARIST.EDU>
To: LINUX-390@VM.MARIST.EDU
Subject: Re: Bash loop failing

Rather than using read can you load the results of the command into an array 
and iterate:


FILES=`ls`

FILE=(${FILES})

for ((i=0; i<${#FILE[@]}; i++))

do

  echo ${i} ${FILE[$i]}

  done

Exit


This should load the variables before the other scripts are invoked.


Neale

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/



--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Neale Ferguson
Rather than using read can you load the results of the command into an array 
and iterate:


FILES=`ls`

FILE=(${FILES})

for ((i=0; i<${#FILE[@]}; i++))

do

   echo ${i} ${FILE[$i]}

   done

Exit


This should load the variables before the other scripts are invoked.


Neale

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Paul Flint

Dear Michael,

Despite your frustration, your email cry for help is music to my ears...

At the VM Workshop I shall be giving a presentation on something I call "Visual 
Bash".  Visual Bash is a framework to help make bash programs easier to manage.


Consequently, my interest is not merely academic, I am really interested in 
bash code under zLinux.


As I understand it, you wish to query several zLinux instances in order to 
ascertain what is going on with each.  If this is indeed what you are up to, 
and I may have gotten this wrong, then the place I would start is the method of 
connection from the query system to the target.  Are you using ssh or something 
else?


While more information about the code would be welcome, I will continue to 
study your email in an attempt to understand the issue.  I might immediately 
suggest blasting the bash code you have out onto git just so we could all 
really sink our shell teeth into it.  The wisdom is that many eyes looking over 
your code will doubtless lead to a solution.  If I can be of any immediate 
help, please do not hesitate to contact me.


Note that my frustration is that the Marist list is most picky.  Hopefully 
this note will post.


Kindest Regards,

Paul Flint
(802) 479-2360
(802) 595-9365 Cell

On Thu, 4 May 2017, Michael MacIsaac wrote:


Date: Thu, 4 May 2017 07:32:00 -0400
From: Michael MacIsaac 
Reply-To: Linux on 390 Port 
To: LINUX-390@VM.MARIST.EDU
Subject: Bash loop failing

Hello list,

This code has been failing for days and I'm at my wit's end.  Maybe someone
on this forum can help.

I've coded a bash script that is supposed to loop through managed Linux
systems. It calls another bash script to get records with 8 fields:

 local cmd="/usr/local/sbin/zlsexpirations -s -l $nodeList"
 local expList# list of nodes and expiration
days
 expList=`$cmd`   # run the command

 ...

So the variable 'expList' has the records. It should then loop through all
the records passing them to the function zSetOneSystem to process one
system at a time. Here's the main loop (the double quotes around expList
are needed to pass a record, not just one token):

 local nextLine
 while read nextLine; do
   zVerbose "calling zSetOneSystem $nextLine"
   zSetOneSystem $nextLine
 done < <(echo "$expList")

This was my first attempt at the loop:

 echo "$expList" |
 while read nextLine; do
   zVerbose "calling zSetOneSystem $nextLine"
   zSetOneSystem $nextLine
 done

Both flavors of the loop above have this behavior:
1) If the -n flag (no operation) is passed, the loop runs fine to
completion.
2) If that flag is not passed, the loop runs, processes one system (which
results in files being changed on disk), but then the loop simply stops.

When I trace it, the 'read nextLine' fails.  I print out 'expList' after
the loop and all records are still in place. How can a sub-process affect
the parent this way? I've narrowed it down to two resulting bash script
calls nested deeper in zSetOneSystem(). If I comment out those two, the
loop succeeds.  If I un-comment either of the two bash scripts, the loop
fails as described.  Strange.

Any help will be appreciated.

Thanks.


--
-Mike MacIsaac

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/



Kindest Regards,



☮ Paul Flint
(802) 479-2360 Home
(802) 595-9365 Cell

/
Based upon email reliability concerns,
please send an acknowledgement in response to this note.

Paul Flint
17 Averill Street
Barre, VT
05641

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread John McKown
On Thu, May 4, 2017 at 6:32 AM, Michael MacIsaac 
wrote:

> Hello list,
>
> ​
>
>
>   local nextLine
>   while read nextLine; do
> zVerbose "calling zSetOneSystem $nextLine"
> zSetOneSystem $nextLine
>   done < <(echo "$expList")
>
> This was my first attempt at the loop:
>
>   echo "$expList" |
>   while read nextLine; do
> zVerbose "calling zSetOneSystem $nextLine"
> zSetOneSystem $nextLine
>   done
>

​Both of the above loops use "read", which reads "lines" from stdin. Is
anything within the while loop reading from stdin (remember that stdin will
propagate to sub-shells & fork()'d processes so they can exhaust the
"parent's" stdin)? If so, that is probably what is causing your problem.​
The "something" is exhausting the stdin. Note that ssh will do this to you
unless your ssh command has the "-n" switch on it.



>
> Both flavors of the loop above have this behavior:
> 1) If the -n flag (no operation) is passed, the loop runs fine to
> completion.
> 2) If that flag is not passed, the loop runs, processes one system (which
> results in files being changed on disk), but then the loop simply stops.
>
> When I trace it, the 'read nextLine' fails.  I print out 'expList' after
> the loop and all records are still in place. How can a sub-process affect
> the parent this way? I've narrowed it down to two resulting bash script
> calls nested deeper in zSetOneSystem(). If I comment out those two, the
> loop succeeds.  If I un-comment either of the two bash scripts, the loop
> fails as described.  Strange.
>
> Any help will be appreciated.
>
> Thanks.
>
>
> --
>  -Mike MacIsaac
>
> --
> For LINUX-390 subscribe / signoff / archive access instructions,
> send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or
> visit
> http://www.marist.edu/htbin/wlvindex?LINUX-390
> --
> For more information on Linux on System z, visit
> http://wiki.linuxvm.org/
>



-- 
Advertising is a valuable economic factor because it is the cheapest way of
selling goods, particularly if the goods are worthless. -- Sinclair Lewis


Maranatha! <><
John McKown

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/


Re: Bash loop failing

2017-05-04 Thread Paul Flint

Dear Michael,

Despite your frustration, your email cry for help is music to my ears...

At the VM Workshop I shall be giving a presentation on something I call "Visual 
Bash".  Visual Bash is a framework to help make bash programs easier to manage.


Consequently, my interest is not merely academic, I am really interested in 
bash code under zLinux.


As I understand it, you wish to query several zLinux instances in order to 
ascertain what is going on with each.  If this is indeed what you are up to, 
and I may have gotten this wrong, then the place I would start is the method of 
connection from the query system to the target.  Are you using ssh or something 
else?


While more information about the code would be welcome, I will continue to 
study your email in an attempt to understand the issue.  I might immediately 
suggest blasting the bash code you have out onto git just so we could all 
really sink our shell teeth into it.  The wisdom is that many eyes looking over 
your code will doubtless lead to a solution.  If I can be of any immediate 
help, please do not hesitate to contact me.


Kindest Regards,

Paul Flint
(802) 479-2360
(802) 595-9365 Cell

/
Based upon email reliability concerns,
please send an acknowledgment in response to this note.

Paul Flint
Barre Open Systems Institute
17 Averill Street
Barre, VT
05641

On Thu, 4 May 2017, Michael MacIsaac wrote:


Date: Thu, 4 May 2017 07:32:00 -0400
From: Michael MacIsaac 
Reply-To: Linux on 390 Port 
To: LINUX-390@VM.MARIST.EDU
Subject: Bash loop failing

Hello list,

This code has been failing for days and I'm at my wit's end.  Maybe someone
on this forum can help.

I've coded a bash script that is supposed to loop through managed Linux
systems. It calls another bash script to get records with 8 fields:

 local cmd="/usr/local/sbin/zlsexpirations -s -l $nodeList"
 local expList# list of nodes and expiration
days
 expList=`$cmd`   # run the command

 ...

So the variable 'expList' has the records. It should then loop through all
the records passing them to the function zSetOneSystem to process one
system at a time. Here's the main loop (the double quotes around expList
are needed to pass a record, not just one token):

 local nextLine
 while read nextLine; do
   zVerbose "calling zSetOneSystem $nextLine"
   zSetOneSystem $nextLine
 done < <(echo "$expList")

This was my first attempt at the loop:

 echo "$expList" |
 while read nextLine; do
   zVerbose "calling zSetOneSystem $nextLine"
   zSetOneSystem $nextLine
 done

Both flavors of the loop above have this behavior:
1) If the -n flag (no operation) is passed, the loop runs fine to
completion.
2) If that flag is not passed, the loop runs, processes one system (which
results in files being changed on disk), but then the loop simply stops.

When I trace it, the 'read nextLine' fails.  I print out 'expList' after
the loop and all records are still in place. How can a sub-process affect
the parent this way? I've narrowed it down to two resulting bash script
calls nested deeper in zSetOneSystem(). If I comment out those two, the
loop succeeds.  If I un-comment either of the two bash scripts, the loop
fails as described.  Strange.

Any help will be appreciated.

Thanks.


--
-Mike MacIsaac

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or 
visit

http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/



Kindest Regards,



☮ Paul Flint
(802) 479-2360 Home
(802) 595-9365 Cell

/
Based upon email reliability concerns,
please send an acknowledgement in response to this note.

Paul Flint
17 Averill Street
Barre, VT
05641

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/

Re: Bash loop failing

2017-05-04 Thread Eric Covener
On Thu, May 4, 2017 at 7:32 AM, Michael MacIsaac  wrote:
>
> When I trace it, the 'read nextLine' fails.  I print out 'expList' after
> the loop and all records are still in place. How can a sub-process affect
> the parent this way? I've narrowed it down to two resulting bash script
> calls nested deeper in zSetOneSystem(). If I comment out those two, the
> loop succeeds.  If I un-comment either of the two bash scripts, the loop
> fails as described.  Strange.


Is $IFS changed and not restored?

--
Eric Covener
cove...@gmail.com

--
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
--
For more information on Linux on System z, visit
http://wiki.linuxvm.org/