Solved

Batch script help - Check file, create log.

Posted on 2009-05-11
6
561 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

13 Experts available now in Live!

Get 1:1 Help Now