appending timestamp to a custom log

Discussion in 'Mac Programming' started by vrinek502, Mar 2, 2006.

  1. macrumors newbie

    vrinek502

    Joined:
    Mar 2, 2006
    Location:
    Greece, Thessaloniki
    #1
    What I'm trying here is to append the timestamp to a text file every minute. This would be useful to tracking time and date of sleeping (for battery life measurement) and for not letting the disk to sleep (major problem with externals while editing video, getting a cup of coffee and waiting 30secs for spin up).
    I know it can be done with a simple shell script, but I don't know how (not much previous Unix experience).

    This is roughly what I try to do:
    Code:
    get current date (in format yyyyMMdd.hhmmss)
    append it (add it to the end) to the file stamp.log in the working directory
    exit
    Can somebody help me?
     
  2. macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    chicago
    #2
    Code:
    #!/bin/sh
    
    LOGFILE=<however you get the name of your logfile>
    
    date "+%Y%m%d.%H%M%S" >> $LOGFILE
    
     
  3. thread starter macrumors newbie

    vrinek502

    Joined:
    Mar 2, 2006
    Location:
    Greece, Thessaloniki
    #3
    Thank you zimv20

    then I just add it to my crontab, right?
     
  4. macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    chicago

Share This Page