Solved

Batch script help - Check file, create log.

Posted on 2009-05-11
6
567 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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