[plug] howto logging result to a log file

Russell Steicke r.steicke at bom.gov.au
Tue Aug 26 23:45:04 WST 2003


On Tue, Aug 26, 2003 at 10:20:31PM +0800, Jon Miller wrote:
> In my script the last thing I need to do is create a log file that
> contains the output of the program plus the date and time of the entry.
> 
> Since I have no idea how to create a log file other than using (correct
> me if I'm wrong) the >> to append to a file, my question is will this
> add a new entry per line with the date to the left.
> What I'm thinking is the following:
> echo `date` mmpf >> /var/log/pstfxst.log 
> Does this seem correct?

No.  Try this:

  date >> logfile
  mmpf >> logfile

Or:

  ( date ; mmpf ) >> logfile

...
> echo `date` mmpf >> /var/log/pstfxst.log
> #
> ## End of Script
> 
> Problem is the last line only produces the date in the log file.  There
> should be 2 lines of information in it.

It will actually put the date followed by the literal string mmpf, which
is probably not what you want.

A better idea might to be to put the output of the script into a log
file right at the start:

  #!/bin/sh

  exec >> logfile
  exec 2>&1

  ... # lines of script
      # Any output you produce here will go into logfile
  date  # including this date.
  mmpf  # and whatever this outputs



-- 
Russell Steicke

-- Fortune says:
If God had a beard, he'd be a UNIX programmer.



More information about the plug mailing list