Solved

Batch script help - Check file, create log.

Posted on 2009-05-11
6
562 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
  • 4
  • 2
6 Comments
 
LVL 95

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 95

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now