batch file outout write to log

folks

i am looking for different batch files to output to a central log file so we can assess their outputs  

in the central log file we require batch file name, time and also a certain value contained from the output of the various batches i.e. "passed" or "failed"

DEVTEST.bat 10/10/13 9:00 am "passed"
OAT.bat 10/10/13 9:05 am "failed"

it should not overwrite the log file but merely add to it can I achieve this

thanks in advance
rutgermonsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim P.Commented:
As part of the batch file you can add in lines like:

echo %computername%  ~ devtest.bat ~ %date% ~ %time% >> \\Server\ShareName\MyLogFile.txt

Open in new window


The computername, date, and time are built-in windows system variables. The double greater than signs means append to a single file. A single greater than signs means overwrite the original file.

Depending on what I'm collecting such as uptime, then I write it like this:
uptime > \\Server\ShareName\%computername%_Uptime.txt

Open in new window

and then use Access to read the files into the DB and put out a daily report.

Uptime can be downloaded here.
0
Bill BachPresident and Btrieve GuruCommented:
At the end of each batch file, simply include a statement like this:
Echo "%0: Date, text to record in log" >>CentralLogFile.txt

The %0 provides the name of the batch file. You can set the date and text based on other variables if you wish -- this should be easiest. The magic that you were missing is the ">>", which appends the text to the end of the log file.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidSenior Oracle Database AdministratorCommented:
In DOS a single right angle is notation to create a file, and doubled for appending.  For example:

echo Hello, > file.txt
echo.       >>file.txt
echo world  >>file.txt

To concatenate literals the syntax is:
( echo Hello, & echo. & echo world ) > file.txt

And using the magic of metadata, your solution is:
( echo %~n & echo %-t & %ERRORLEVEL% ) > file.txt

where ERRORLEVEL is populated with the value of what result is given to the return variable (0, or -1).

I recommend you query a search engine for more on DOS metadata, and return codes, to decide how you want to substitute a string value for the result choices.  Also, the specific coding is not tested, your actual results may differ.

dvz
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Steve KnightIT ConsultancyCommented:
i think you have all you need there except to say the %0 that has been mentioned is the batch file name but can be the complete path to it.  if you always just want the name use:

%£nx0  where n is name and x is extension.  for some reason can't type character needed here, the £ is the small squiggly line character...

steve
0
BillDLCommented:
%~nx0
0
gelonidaCommented:
How are these batch files started? ( by a machine, by a user, by another program)

Could it ever happen that two batch files are run at the same time? In this case you had to make sure that there is no access conflict when accessing the lock file.

Can you modify the existing log files?
0
gelonidaCommented:
Pls ignore my comment. I was reading from a mobile app. And somehow due to NW problems I didn't see that you have already allaanswers. The only potential issue might occur if two bat files try yo log at the same time. Will happen very rarely, but you might loose one log entry due to file access errors
0
rutgermonsAuthor Commented:
folks, thanks for the help however how can I from the batch extract the values

"passed" or "failed"

into the log file?i am not looking for the entire output of the batch, merely only the status i
0
Steve KnightIT ConsultancyCommented:
how do we know if it failed or passed?

If you tell us what is in the batch file, does it give an errorlevel to say pass or fail or do we need to look for something in the output of it?
0
DavidSenior Oracle Database AdministratorCommented:
I alluded to setting the return variable in 39567935, but had wanted you to search some on your own.  Okay, another hint or two.  Note the "slant" word must be replaced with the right slash character.

EXIT [slashB] [exitCode]

  slashB          specifies to exit the current batch script instead of
              CMD.EXE.  If executed from outside a batch script, it
              will quit CMD.EXE

  exitCode    specifies a numeric number.  if slashB is specified, sets
              ERRORLEVEL that number.  If quitting CMD.EXE, sets the process
              exit code with that number.

AND

@echo off
setlocal <some literal>
ping 127.0.0.1
if "%errorlevel%"=="0" cls &Echo Success.
if "%errorlevel%"=="1" cls &Echo Fail
endlocal
0
tliottaCommented:
Are you trying to change all .BAT files to leave messages in a log file? Or are you trying to find some way to monitor success or failure from outside of the batch processes?

Tom
0
rutgermonsAuthor Commented:
tom, the latter

basically the batch does an RMI call to the application and gets a response contained somewhere in the output i.e. "passed" or "failed"

because i have about 30 apps to monitor I would like to obtain this info in a separate  file
0
tliottaCommented:
...the batch does an RMI call to the application...

"The" batch? A single .BAT file? Or is that just shorthand for all the .BAT files you're interested in?

Are you looking for an indication of success/failure of the .BAT? ...of RMI? ...or of the invoked app method? (Or any/all of those?)

Can you give a fuller description of exactly what's going on?

Tom
0
Steve KnightIT ConsultancyCommented:
I would suggest you post the output of a fail and pass as suggested firstly.  

You can check for certain terms with something like

mycmd.exe | find /i "passed" && echo has passed

but to think of here, does finding the word "passed" mean passed, could it also have the word "failed".  If it has neither is that different, or classed as a "fail" etc.

What might be best here IMHO is you do it like this:

Each machine runs and logs to \scripts\mylog.txt or whatever
Central checking scripts grabs mylog.txt from each, renames it to mylog.old and appends it to mylog.archive.txt or something on that machine, or just deletes if no archive needed.   Then you check these grabbed log files in the central place.
0
rutgermonsAuthor Commented:
I took a bit of a detour and found a code(on E-E) to extract the values i was looking from a log into another log, the initial log is created by the batch anyway and meets my needs exactly (albeit I still need to add filename/date and time into it)

strFolder = "C:\test"
Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
 
 'create output file
 strOutputName = "output.txt"
 Set objOut = objFSO.GetFolder(strFolder).CreateTextFile(strOutputName, True)
 
'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder).Files
        'if its a log file
        If Right(LCase(objFile.Name), 4) = ".log" Then
               'open log file
                Set objFile = objFSO.OpenTextFile(objFile.Path, intForReading, False)
                'loop thorugh log file
           Do While Not objFile.AtEndOfStream
                        strData = objFile.ReadLine
                        If InStr(strData, "passed") Or InStr(strData, "failed") Then objOut.WriteLine strData + Now()
                Loop

                objFile.Close
        End If
Next
objOut.Close
'MsgBox "Finished."
0
rutgermonsAuthor Commented:
I've requested that this question be deleted for the following reason:

found own solution

strFolder = "C:\test"
Dim objFSO
Dim objFile
Dim objOut
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
 
 'create output file
 strOutputName = "output.txt"
 Set objOut = objFSO.GetFolder(strFolder).CreateTextFile(strOutputName, True)
 
'for each file in directory
For Each objFile In objFSO.GetFolder(strFolder).Files
        'if its a log file
        If Right(LCase(objFile.Name), 4) = ".log" Then
               'open log file
                Set objFile = objFSO.OpenTextFile(objFile.Path, intForReading, False)
                'loop thorugh log file
           Do While Not objFile.AtEndOfStream
                        strData = objFile.ReadLine
                        If InStr(strData, "connected") Or InStr(strData, "refused") Then objOut.WriteLine strData + Now()
                Loop

                objFile.Close
        End If
Next
objOut.Close
'MsgBox "Finished."
0
Steve KnightIT ConsultancyCommented:
You did suggest you wanted a batch file, and we did ask what was in the log files but got no information, it seems you wanted to look for the text "refused" or "connected".  You could do the same with a FIND or FINDSTR command in batch like was suggested as the guesswork we had to work on.

http:#a39569806

I suppose looking down your questions and their grading.... deleted, B's and C's it doesn't get me too interested in trying to help another time.

Anyone else going to object to deletion?
0
gelonidaCommented:
Well I personally didn't really contribute to this question, but I must admit, that my first reaction when seeing the delete request was also, that it would be better (more courteous) to accept the own answer as solution, mark some other answers (not mine) as assisted solutions and distribute points.

Most people giving answers here are volunteers, are doing the best to try to guess whatever is not mentioned in the question in order to give a constructive answer.
0
DavidSenior Oracle Database AdministratorCommented:
It appears that the question criteria, and the solution, are significantly different.  Nonetheless, we appreciate that the asker is a paying customer and hope that he or she remains satisfied with the service provided.
0
tliottaCommented:
I'm not sure what to comment. The described solution not only doesn't seem to answer the question, it also doesn't seem complete. It's hard to be sure, but it looks as if it only checks whether RMI connected or not without seeing if the app method succeeded or was even invoked. Hard to be sure of anything without knowing where the input .LOG file originated.

I have no idea how the question ought to be closed, but a straight deletion doesn't seem right. Some review seems appropriate.

Tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.