bash padding

Hi all

Is there a way to pad the output of a bash script
see that code below

for i in `sed -n '/Start Printer/,/End Printer/p' /u/ab/scripts/hosts.conf | awk '!/^#/ {print $2}' | egrep -v 'broke|primera' `; do 


    pages=`snmpget -Ov -v1 -c public $i sysLocation.0 | awk '{print $2}'`
    echo $i $pages
 
done

so it will output

prawn 211sa

i want to be able to pad it so it is alligned nicely

i.e

prawn       211sa
octopus    203ms

many thanks

Adam

Use printf instead of echo:

printf "%-10s %s\n" "$i" "$pages"

thanks worked like a treat, lastly ( casue i am coming to the end of my programming knowledge) if i want to put some error checking in, i get one result

Timeout: No Response <hostname>

is there a way i can just get it to spit out a message

<hostname>    hostdown 

or something similar,

btw i have made $i the hosthame

thanks

Hi, try (quick and dirty):

set -o pipefail
if pages=`snmpget -Ov -v1 -c public "$i" sysLocation.0 2>/dev/null | awk '{print $2}'`
then  
  printf "%-10s %s\n" "$i" "$pages"
else
  printf "%-10s %s\n" "$i" hostdown
fi
set +o pipefail