Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch script help - Check file, create log.

Posted on 2009-05-11
6
Medium Priority
?
570 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

722 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