Uniform Spacing in the message

Hello,

I am running a script which sends an output as an email; I am having issues with the spacing being not uniform in the message. Snippet of the code and email message below:

 if [[ $Backup == '' ]] then echo "$Hostname\tMISSING\tHMCBackup" >> $BackupMsg
      else if [[ $Backup > $Current ]] then echo "$Hostname\tGood\tHMCBackup" >> $BackupMsg
      else if [[ $Backup < $Current ]] then echo "$Hostname\tStale\tHMCBackup" >> $BackupMsg; fi; fi; fi; done < $SupportedHosts

Email/Output

fcop23Stale	HMCBackup
fcop24MISSING	HMCBackup
fcop25MISSING	HMCBackup
fcopc6MISSING	HMCBackup
ecopc22	Stale	HMCBackup
ecopc23	Stale	HMCBackup
ecopc24	MISSING	HMCBackup
ecopc25	MISSING	HMCBackup
ecopc26	MISSING	HMCBackup

I would like the whole message to be like

ecopc24	MISSING	HMCBackup
ecopc25	MISSING	HMCBackup
ecopc26	MISSING	HMCBackup

If partial script shown is part of a loop, try:

while read Hostname Backup Current
do
if [[ $Backup == '' ]] then
   printf "$Hostname\tMISSING\tHMCBackup\n"
else
   if [[ $Backup > $Current ]]
   then
      printf "$Hostname\tGood\tHMCBackup\n"
   else
      if [[ $Backup < $Current ]]
      then
         printf "$Hostname\tStale\tHMCBackup\n"
      fi
   fi
fi
done < $SupportedHosts | expand > $BackupMsg

You may want to look at the 'tabs' command.

This controls the default number of spaces.

Hello rdrtx1,

I tried your code and I still get the same output.

your issue is with the number of characters in your hostname (i.e, fcop23 has 6 and ecopc22 has 7) that is throwing off the tab spacing since tab is placed in relation to the last character of the word preceding it.

change this

echo "$Hostname\tMISSING\tHMCBackup" >> $BackupMsg

to

echo "$Hostname,MISSING,HMCBackup" | tr ',' '\t' >> $BackupMsg

Well, it is giving the output as below without any spaces

fcop23\Stale\HMCBackup
ecopc23\Stale\HMCBackup

no spaces at all

What happens if you precede the command with

tabs=15

which should set tab positions every 15 characters?

tabs=15

did not help, still the same output with no uniform spacing

try again ...

echo "$Hostname,MISSING,HMCBackup" | tr ',' '\t' >> $BackupMsg

recheck your edits. if still an issue, post your edited code.

I tried the code as posted

echo "$Hostname,MISSING,HMCBackup" | tr ',' '\t' >> $BackupMsg

still the same. The tab spaces are off

while read Hostname Backup Current
do
if [[ $Backup == '' ]] then
   printf "$Hostname\tMISSING\tHMCBackup\n"
else
   if [[ $Backup > $Current ]]
   then
      printf "$Hostname\tGood\tHMCBackup\n"
   else
      if [[ $Backup < $Current ]]
      then
         printf "$Hostname\tStale\tHMCBackup\n"
      fi
   fi
fi
done < $SupportedHosts | expand | sed 's/^/<pre>/; s/$/<\/pre>/;' > $BackupMsg

I am getting the below as output

<pre>eccas2167       STALE   mksysb</pre>
<pre>eccas2355       MISSING mksysb</pre>

Can I just check that there are actually commas in the raw output. It doesn't look like it to me and so the tr will have no effect.

Am I missing something? :confused:

Perhaps you need to use printf instead of echo, making sure that you add in the required newlines, e.g. printf "Hello\tworld.\n"

Surely it's not that simple?

Another possibility is that your tr has fields wrapped in single quotes, which forces the content to be literally the characters as typed. If you use double quotes, that may help it interpret \t as a tab character.

Does that help at all?

Robin