This code has been failing for days and I'm at my wit's end. Maybe someone 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:
- If the -n flag (no operation) is passed, the loop runs fine to completion.
- 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.