I need some help making a service application batch file.
In short, the application checks if there are any new files in a folder, if so it writes to a log file (Results.txt).
The problem is that if there are no “results” in the folder in 24 hours there is usually something wrong. (Either the service has crashed or there is a network problem.) So I need to write a batch script to check if the Results.txt file has been altered in the last 24 hours.
My plan is to have a batch file run every 24 hours that checks the md5sum of Results.txt to see if it has changed. However, I have no idea how to go about this. In pseudocode, it would look like this:
if not exist old.txt echo. > old.txt & fc "md5.txt" "old.txt"
%md5sum% Results.txt > md5.txt
set equal=no
if md5.txt==old.txt set equal=yes
if equal=no echo No results found in 24 hours >> log.txt
How about going simple? No fancy MD5, just the output of the
dircommand! This works because the dir command output will be exactly the same no matter when it is run if nothing has changed in the directory it is checking.For Help and More Options see:
Example:
If you want to hide all the output of the batch script just throw in a
> nulbehind thefcline.Update:
In light of the new information provided.
So you just need to check the last write time stamp of the Results.txt file. As long as you do not write to the file when there has been no changes and update the time stamp.
Or even better yet, if all you care about is whether or not a folder has had any activity inside of it, just check that folder’s ‘last write’ time stamp. If the time stamp is older than 24 hours you can process your no results found in 24 hours.
Use the
/t:woption with thedircommand and you can parse the time stamp that you need.TLDR: KISS
Update 2:
Here is an example script showing how to get a pure breakdown of the directory information.
Answer:
Here is a script illustrating an easy way to get and compare the time stamps. Setup a scheduled task to run this script every 24 hours and if the time stamp has not changed since the last run, it will print out a message to the log file.