The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: printf command
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-07-2002
FIRE FIRE is offline
Registered User
  
 

Join Date: Jul 2002
Location: South of Holland
Posts: 10
printf command

I want to make a logfile with error messages, like this:
(collumms: CUSTNR DATE TIME ERROR MESSAGE)

Code:
 
102      20020807 135417 1 Uptime server is more than 6 months
5        20020808 111335 3 Backup not Ok!
2001     20020808 120428 6 Free space at server1 is less than 20%
etcetera

I made this script:


Code:
CUSTNR=101
DATE=`date +%Y%m%d`
TIME=`date +%H%M%S` 
ERROR=1
MESSAGE="Uptime server is more than 6 months"

printf "%-8s %-10s %-6s %-6s %-80s\n" $CUSTNR $DATE $TIME $ERROR $MESSAGE >> error.log

But the variabele MESSAGE is printed wrong. The logfile looks something likes this:

Code:
 
102      20020807 135417 1 Uptime 
server   is       more   than 6 months

One of the problems are the spaces between de words in the MESSAGE strings.
How can I solve this/these problems?