Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Nov 2001
    Location
    Qld, Australia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Batch File

    Hello there,

    I have a batch file that does a file upload and writes to a log file. A line gets appended each time saying if the upload was successful or not. How do I get a date and time to also get appended so that I know when the job succeeded or failed - any ideas ?

    cheers,

    Adam

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    I'm sure there is a neater solution but you could do worse than doenload a utility called <A target="_blank" HREF=http://www.simtel.net/pub/pd/9347.html>Now</A> which can be used for a variety of date-based batch files.

    I found their example didn't work on W2K, but<pre>NOW ECHO CREATED ON [day] [dy] [month] [year] AT [hh]:[mm] >> log.txt</pre>

    appended the date and time to a file called log.txt OK.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Cairns, Queensland, Australia
    Posts
    885
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    Being something of an old hand at DOS I second Lief's suggestion. If there is a neater solution I would be happy to hear about.
    Granville

  4. #4
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    Funnily enough, I've just been working on a couple of batch files - first time in many years. I wanted to rename a file with today's date, so I had done half the legwork!
    I've worked out how to get the date and time to do the file rename, but couldn't see how to write that information to a file. I suspect W2K may have some limitations when it comes to batch files.

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    How about:

    <pre>ECHO.|DATE|FIND /I "Current">>C:LogfilesMyLog.Log
    ECHO.|TIME|FIND /I "Current">>C:LogfilesMyLog.Log
    </pre>


    No space betweemthe "O" in ECHO and the dot after it.
    Legare Coleman

  6. #6
    New Lounger
    Join Date
    Nov 2001
    Location
    Qld, Australia
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    legare,

    thanks for the help. I'm having a little trouble getting it to work as it probably should. Here's how I've modified it to use in my batch file:

    if "%LOGGING%"=="YES" echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
    if "%LOGGING%"=="YES" echo.|DATE|FIND /I >>%SGETDIR%IDEFETCH.LOG
    if "%LOGGING%"=="YES" echo.|TIME|FIND /I >>%SGETDIR%IDEFETCH.LOG

    But here' s what I get in the log file:

    Already up to date with the latest virus identities
    FIND: Parameter format not correct
    FIND: Parameter format not correct

    Any ideas ?

    cheers,

    Adam

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    I think you will need to do it like this:

    <pre>if NOT "%LOGGING%"=="YES" GOTO NOTLOGGING
    echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
    echo.|DATE|FIND /I "CURRENT">>%SGETDIR%IDEFETCH.LOG
    echo.|TIME|FIND /I "CURRENT">>%SGETDIR%IDEFETCH.LOG
    :NOTLOGGING
    </pre>

    Legare Coleman

  8. #8
    Star Lounger
    Join Date
    Feb 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    Can I ask why the echo. and find?
    How about (tested on NT):

    if NOT "%LOGGING%"=="YES" GOTO NOTLOGGING
    echo Already up to date with the latest virus identities >>%SGETDIR%IDEFETCH.LOG
    DATE /t>>%SGETDIR%IDEFETCH.LOG
    TIME /t>>%SGETDIR%IDEFETCH.LOG
    :NOTLOGGING

    Also, does anyone know where to find a comprehensive batch file guide for NT? Something that explains in detail the command extensions for the SET command, for instance. Maybe some clever examples and tricks, that sort of thing... ?

  9. #9
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    My code came from back in DOS 5. The ECHO. was a special syntax of ECHO to get it to echo a CR/LF. This was then piped to the DATE/TIME command to reply to its prompt for you to enter a new date/time. The Find was because DATE/TIME displayed multiple lines, and the one that contained the word "Current" was the one that contained the date/time. There was no /t parameter on the DATE/TIME commands. If your code works, then I assume that this parameter eliminates the need for ECHO. and FIND on NT. As far as I know, that will not work on WIN 98 and earlier.
    Legare Coleman

  10. #10
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help with Batch File

    Some info on batch files <A target="_blank" HREF=http://gearbox.maem.umr.edu/~batch/intrin1.htm>here</A>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •