Solved

Batch script help - Check file, create log.

Posted on 2009-05-11
6
569 Views
Last Modified: 2012-05-06
Hi there,

I'd appreciate if someone would be able to help me construct a small batch script that I can set to run once a day on a scheduled task that checks a folder on a server that a logfile is there.
Basically, we have folder that is supposed to fill up with log files from a process that runs once a day. We get one log file a day and each file has the days date appended to the file name.

Occasionally these log files aren't being created or copied to the folder, so to save someone logging onto the machine and manually checking for the logfile each day I'd like to set a script to do this for me automatically.
Each day we get something similar to this:

Logfile11-05-2009.log
Logfile10-05-2009.log
Logfile09-05-2009.log
Logfile08-05-2009.log

Each day a new logfile is created, and the date of the day is appended to the file name. I need the script to check that the new days logfile has arrived, then send me an email to say yes it has arrived, or no it hasn't arrived.

I can create the email part of the script myself, but I don't have much of a clue as to where or what to start to do the 'checking' part.

As I mentioned, each day of the month we get a new file, and the days date is appended to the file name, so some months we will get 31 log files, other months we will get 30 etc etc (you get the idea!)
It doesn't specifically have to be a Batch script, but I'm so utterly ignorant about anything like this I thought that way might be the easiest for me to understand (plus as mentioned above I can do the email bit myself - where as using anything else I'd have to ask for help with the email bit as well! Lol)

If someone could help me with this I'd appreciate it.

Many thanks in advance.


0
Comment
Question by:Nicola_Bourne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 24352851
The key here is reading the date.  I don't know how your version of Windows is set to display the date.  Can you post a screen shot with the following two commands run in a command prompt:

echo %date%
date /t

Then the checking would be something like this:
IF EXIST "x:\path\to\your\log files\Logfile%date:~7,2%-%date:~4,2%-%date:~-4%.log" DoSomeCommand

Note- that may not work depending on how the date is output by the commands I ask about first.  It should work where the date is output in the format DAY MM/DD/YYYY.  If it's different, then it would need to be adjusted.

In short, %date:~7,2% means to take the 2 characters, starting at the 7th, in the %date% variable.  Similar for %date:~4,2%.  The last one, %date:~-4% means to take the LAST 4 characters in the %date% variable.  With that you can try to adjust it yourself, or post the information and we can adjust it for you.
0
 

Author Comment

by:Nicola_Bourne
ID: 24352897
Thanks very much for that Leew,

Screenshot attached.
date.JPG
0
 
LVL 96

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 24352931
Ok, try:

IF EXIST "x:\path\to\your\log files\Logfile%date:~0,2%-%date:~3,2%-%date:~-4%.log" DoSomeCommand

Replacing the path with the appropriate path and the "DoSomeCommand" with a command you want to do.  (Actually, you want to do something only if the is not there, right?  In that case try:

IF NOT EXIST "x:\path\to\your\log files\Logfile%date:~0,2%-%date:~3,2%-%date:~-4%.log" DoSomeCommand
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:Nicola_Bourne
ID: 24353384
Thanks Lee, appreciate the help - I'll try that out :-)
0
 

Author Comment

by:Nicola_Bourne
ID: 24355329
Hi Lee,

Sorry, just one more question, how would I adjust if the date is set to echo like this:

        Mon 05/11/2009

(screenie attached)

Thanks again.
date-2.JPG
0
 

Author Comment

by:Nicola_Bourne
ID: 24355398
Sorry to be a pain, I've just noticed one thing....

The logfiles we are using are unfortunately (and I can't change this) dated in a different way than how the server seems to output the date.

I.e. the server holds the date in this format:

        Mon 05/11/2009

...and the logfile is named like this:

        statistics.log.2009-05-10

Is this going to make life difficult at all?

Thanks again.


0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question