[plug] howto logging result to a log file
Jon Miller
jlmiller at mmtnetworks.com.au
Wed Aug 27 06:46:50 WST 2003
Thanks Russell,
That gave me what I needed.
Jon
On Tue, 2003-08-26 at 23:45, Russell Steicke wrote:
> 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
--
Jon Miller <jlmiller at mmtnetworks.com.au>
MMT Networks Pty Ltd
More information about the plug
mailing list