It's been a while since i have butted heads against scripts, but ... I am confused! You set variable environmenthosts from the 1st parameter passed to the command, but then it is used in a loop which suggests it's a list of name - I presume it looks something like: ./YourCommand "host1 host2 host3" PuppetFacts User UserPwd?
In addition I'm not a fan of the way you are processing that list of hosts and not really seeing the need to involve xargs? Would not something like

Code:

for i in $environmenthosts
do
/bin/scpass $userpassword $releaseartifact $user@$i:/tmp
done

do the job?
For the second script, seeing as it's tcl, could you not drop the arg=[lindex ..] list of commands and just specify [lrange $argv 2 end]?

Last edited by SimonJM; July 26th, 2015 at 04:59 PM.

The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Many thanks for your feedback... you are indeed correct that the 1st arg is in fact a single string with whitespace separated hostnames.

The reason for using xargs is that this command needs to run in parallel across all hosts/boxes. I don't want this to be achieved through using background processing as I want the stdout of all concurrent executions of the for loop across all boxes to be piped to the current shell's stdout. I have omitted how this is achieved from the above example, but basically, I am using tee to output to both stdout and to a file. The reason I need all concurrent executions to be running in the foreground and outputting to stdout is that this script is to be run from a continuous integration app (jenkins or bamboo) and I want to be able to see the output during execution from within the UI of the CI server.

Interesting point about the tcl script. Could you expand on how you might incorporate that range expansion into the above script?

Appreciate your thoughts on how I might be able to achieve parallel execution of sshpasscmd across multiple boxes while having interlaced output coming from the stdout of all running executions across all boxes (environmenthosts)?

I always had/have to sit and think about logging when lobbing commands across the network, so I feel your pain! I presume the output of the scppass is not a problem as it's actually being driven by the server running the actual base command (if that's not the case my memory is worse than I thought! ) So, to the second loop, the one that runs stuff on the target/remote server(s)!
In theory (i.e., to the best of my knowledge!) you could wrap the whole thing in {} and deal with the output en masse that way?

So far as the tcl bit goes, as 'all' you seem to be doing is 'un-listing' and 're-listing' the arguments you should be able to achieve the same thing with [lrange $argv 2 end] (You may need to wrap that in [string ...], so your spawn command would become:

The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc