in reply to Script to manipulate data is not giving me any output
is identical tocat /mnt/scripts/lagtime/tmp/input.txt |awk '{printf "%1.50s\t%0.60s\t +%0.45s\t %0.45s\n", $1, $2, $3, $4}' | sh /mnt/scripts/lagtime/calcul +ate_lag.sh > /tmp/snapvault_status.out.out;
Moreover, elsewhere, you claim that Awk is needed to put the columns in the right place... - a palpably untrue claim since you're simply using awk to strip out and re-format the first 4 columns, leaving the ordering untouched.awk '{printf "%1.50s\t%0.60s\t%0.45s\t %0.45s\n", $1, $2, $3, $4}' /mn +t/scripts/lagtime/tmp/input.txt | sh /mnt/scripts/lagtime/calculate_l +ag.sh > /tmp/snapvault_status.out.out;
The problem is that the last output file is empty - this shouldn't come as a huge surprise if the last of the input lines causes an empty line to be written to the output - via the /mnt/scripts/lagtime/calculate_lag.sh script - since, within the loop, the output file is rewritten, c/w being appended to, each time.
In the light of this, I think I'd be tempted to
use warnings; use strict; use autodie; my @HOSTS = qw/datab01 datab02 datab03/; my $IN_FILE = q(/mnt/scripts/lagtime/tmp/input.txt); my $OUT_FILE = q(/tmp/snapvault_status.out.out); open IN_FILE, qq/>$IN_FILE/; foreach my $host (@HOSTS) { foreach (`ssh $host snapvault status | tail -n +3`) { local @_ = split; # Avoid warnings printf IN_FILE "%1.50s\t%0.60s\t%0.45s\t %0.45s\n", $_[0], $_[ +1], $_[2], $_[3]; } } close IN_FILE; open IN_FILE, qq/<$IN_FILE/; open OUT_FILE, qq/>$OUT_FILE/; while (<IN_FILE>) { print OUT_FILE `sh /mnt/scripts/lagtime/calculate_ +lag.sh $_` } close IN_FILE; close OUT_FILE;
|
|---|