Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set padding character to dot 2

Status
Not open for further replies.

daFranze

Technical User
Dec 29, 2003
1,334
DE
ok, this is just cosmetics but... :)

My Script acts similar to init (or rc depending on the UNIX), it executes a Script and prints out a message about the return code
The output should look like this:
2008-11-18 11:53:27 Starting Application Blahblah ............. FAILED
2008-11-18 11:54:03 Starting Daemon Whatelse .................. OK

but it looks like this (no padding at all):
2008-11-18 11:53:27 Starting Application Blahblah FAILED
2008-11-18 11:54:03 Starting Daemon Whatelse OK

but it looks like this (padding icharacter is a blank):
2008-11-18 11:53:27 Starting Application Blahblah FAILED
2008-11-18 11:54:03 Starting Daemon Whatelse OK

Well, I have som experience in writing C/C++ code, I could write my own function, BUT

Is there an easy way to use printf, awk or something to set padding to eg a dot? (I am on a hp-ux 11.23 box if this is an issue)

Best Regards, Franz
--
System Manager (Solaris, HP-UX, Linux, some networking, some SAN)
 
A starting point:
x='.......................................................'
y='2008-11-18 11:53:27 Starting Application Blahblah'
z='2008-11-18 11:54:03 Starting Daemon Whatelse'
echo `expr substr "$y $x" 1 70` FAILED
echo `expr substr "$z $x" 1 70` OK

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or you can use printf command:

[tt]
dots='......................................................................'

date=$(date +'%Y-%m-%d')
time=$(date +'%T')
mesg='Starting Application Blahblah'
...
rslt=FAILED
printf "%10s %8s %-50.50s %s\n" ${date} ${time} "${mesg} ${dots}" ${rslt}

date=$(date +'%Y-%m-%d')
time=$(date +'%T')
mesg='Starting Daemon Whatelse'
...
rslt=OK
printf "%10s %8s %-50.50s %s\n" ${date} ${time} "${mesg} ${dots}" ${rslt}
[/tt]

HTH,

p5wizard
 
thank you for your ideas, they where very helpful!

Best Regards, Franz
--
System Manager (Solaris, HP-UX, Linux, some networking, some SAN)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top