Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Append the timestamp before and after the data in the logfile

by McDarren (Abbot)
on Dec 22, 2005 at 05:12 UTC ( [id://518477]=note: print w/replies, xml ) Need Help??


in reply to Append the timestamp before and after the data in the logfile

Is there any commands available in the shell script itself?
Yes, there is. It's called the date command.

This is not how I would choose to do this, but to answer your question directly, you could simply do:

date > test.log ; perl test.pl >> test.log ; date >> test.log

Note the use of >> rather than >, this ensures that your logfile is appended to rather than overwritten.

You should also check man date for the various formatting options.

Cheers,
Darren :)

Replies are listed 'Best First'.
Re^2: Append the timestamp before and after the data in the logfile
by Kanji (Parson) on Dec 22, 2005 at 05:33 UTC

    To save some typing, you can group the commands together in a subshell and redirect the subshell's output instead.

    ( date; perl test.pl; date ) > test.log

        --k.


      No need to spawn a subshell:
      { date; perl test.pl; date; } > test.log
      will do. At least in bash, that is...
Re^2: Append the timestamp before and after the data in the logfile
by kulls (Hermit) on Dec 22, 2005 at 06:05 UTC
    hi,
    Thanx for your reply.I'm proceeding with 'time' command instead of 'date'.
    -kulls
      erm, are you sure this is what you want?

      You said that you wanted a timestamp. The time command will certainly not give you that.

      From man time

      time - run programs and summarize system resource usage

      An example of what you get when you use time is:

      time perl -e 'print "hello world\n"' hello world real 0m0.006s user 0m0.000s sys 0m0.000s

      Unless I seriously misunderstood your original question, then I doubt very much this is what you want.

      Update: It just occurred to me that you're probably running this on Win32, in which case yes, you could use time. You probably want to add the /T switch.

        hi,
        yes.This too also i needed. I updated my question too. But how can i append this information to the log file.As of now ,i just replace the 'date' with 'time' and start working in that.
        Ok.Shall i do like this,
        %usr>(perl test.pl; time perl test.pl;) > test.log
        this is correct ?

        -kulls

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://518477]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found