So I have been struggling with a task to create a script which executes commands on remote hosts in parallel. While I have that working using the parallell::forkmanager module, I am getting whitespace from the command output that I have been unable to remove. One would think this would be simple but it eludes me. I have created the following sub to execute the commands and return the output as well as exit status.
And passing a simple command such as 'uptime', 'date' or 'hostname' gives me a leading space or a trailing carriage return that I am unable to remove with chomp or s/// SAMPLE OUTPUT:sub exitstatus { ## # Exit Status Trap # Arguments required: &exitstatus(cmd); # # Examples: # my ($output, $status) = &exitstatus('/bin/cp', '/somepath/somefile +', '/some/new/location'); # my ($output, $status) = &exitstatus($somecommand); # # Returns text output from the command as well as exit status. ## my $command = join ' ', @_ or die "No command specified\n"; if ($debug) { print "command: $command\n"; } ($_ = qx{$command 2>&1}, $? >> 8); }
My question is this. Is there a way to trim the whitespace of the command output (both leading and trailing) without removing or conflicting with the exit status of the command. Every time I attempt to craft such code, I am met with the error message:Running: 'hostname' on admin001: admin001 Running: 'uptime' on admin001: 09:42:50 up 333 days, 22:24, 4 users, load average: 0.05, 0.10, 0.3 +6 Running: 'date -I' on admin001: 2014-05-29 Running: 'hostname' on mon001: mon001 Running: 'uptime' on mon001: 09:42:51 up 333 days, 22:23, 1 user, load average: 1.18, 0.74, 0.57 Running: 'date -I' on on001: 2014-05-29
Useless use of right bitshift (>>) in void context at - line 437.
In reply to Erroneous Whitespace by lokista
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |