PC Review


Reply
Thread Tools Rate Thread

Batch file error reporting

 
 
=?Utf-8?B?bWF0dHIyMTEw?=
Guest
Posts: n/a
 
      17th May 2006
I've created a batch file that will schedule a task on a list of computers.
I'v tried to add an error log that will report if there where any errors. It
alwasys reports the same error even if it fails. I'm not sure if I have the
error handling setup correct please help.

Here is the code
@Echo off
cd\

cls

Set /P Ti=Enter the time you wish job to run:
Set /p LO=Enter the location of script or program to run:

::1. Configure the path to the PS input list
Set PCList=c:\it\pc.txt

For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call :Remote)

GOTO :EOF

:remote

at \\%Node% %ti% /interactive "%LO%"


if not errorlevel 1 goto end
echo An error occurred during
:end
echo Job completed: %node% >> c:\logs\batch.log


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      17th May 2006

"mattr2110" <(E-Mail Removed)> wrote in message
news:5E60A022-CC87-4CCD-9A3F-(E-Mail Removed)...
> I've created a batch file that will schedule a task on a list of

computers.
> I'v tried to add an error log that will report if there where any errors.

It
> alwasys reports the same error even if it fails. I'm not sure if I have

the
> error handling setup correct please help.
>
> Here is the code
> @Echo off
> cd\
>
> cls
>
> Set /P Ti=Enter the time you wish job to run:
> Set /p LO=Enter the location of script or program to run:
>
> ::1. Configure the path to the PS input list
> Set PCList=c:\it\pc.txt
>
> For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call :Remote)
>
> GOTO :EOF
>
> :remote
>
> at \\%Node% %ti% /interactive "%LO%"
>
>
> if not errorlevel 1 goto end
> echo An error occurred during
> :end
> echo Job completed: %node% >> c:\logs\batch.log
>
>


You have to enable delayed expansion so that %Node% gets
set the way it should. You must also ensure that your log directory
exists. Try this variant:

Line1 @Echo off
Line2 setlocal EnableDelayedExpansion
Line3
Line4 ::1. Configure the path to the PS input list
Line5 Set PCList=c:\it\pc.txt
Line6 if not exist c:\logs md c:\logs
Line7
Line8 Set /P Ti=Enter the time you wish job to run:
Line9 Set /p LO=Enter the location of script or program to run:
Line10 if "%Ti%"=="" goto :eof
Line11 if "%LO%"=="" goto :eof
Line12
Line13 For /F "tokens=*" %%i in (%PCList%) do (
Line14 at \\%%i %ti% /interactive "%LO%"
Line15 if !ErrorLevel!==0 (
Line16 echo Job scheduled on %%i >> c:\logs\batch.log
Line17 ) else (
Line18 echo An error occurred when scheduling the task on %%i >>
c:\logs\batch.log
Line19 )
Line20 )
Line21
Line22 endlocal


 
Reply With Quote
 
=?Utf-8?B?bWF0dHIyMTEw?=
Guest
Posts: n/a
 
      17th May 2006
OK tried it, it schedules the job but nothing in the log file. I'm not sure
why?

"Pegasus (MVP)" wrote:

>
> "mattr2110" <(E-Mail Removed)> wrote in message
> news:5E60A022-CC87-4CCD-9A3F-(E-Mail Removed)...
> > I've created a batch file that will schedule a task on a list of

> computers.
> > I'v tried to add an error log that will report if there where any errors.

> It
> > alwasys reports the same error even if it fails. I'm not sure if I have

> the
> > error handling setup correct please help.
> >
> > Here is the code
> > @Echo off
> > cd\
> >
> > cls
> >
> > Set /P Ti=Enter the time you wish job to run:
> > Set /p LO=Enter the location of script or program to run:
> >
> > ::1. Configure the path to the PS input list
> > Set PCList=c:\it\pc.txt
> >
> > For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call :Remote)
> >
> > GOTO :EOF
> >
> > :remote
> >
> > at \\%Node% %ti% /interactive "%LO%"
> >
> >
> > if not errorlevel 1 goto end
> > echo An error occurred during
> > :end
> > echo Job completed: %node% >> c:\logs\batch.log
> >
> >

>
> You have to enable delayed expansion so that %Node% gets
> set the way it should. You must also ensure that your log directory
> exists. Try this variant:
>
> Line1 @Echo off
> Line2 setlocal EnableDelayedExpansion
> Line3
> Line4 ::1. Configure the path to the PS input list
> Line5 Set PCList=c:\it\pc.txt
> Line6 if not exist c:\logs md c:\logs
> Line7
> Line8 Set /P Ti=Enter the time you wish job to run:
> Line9 Set /p LO=Enter the location of script or program to run:
> Line10 if "%Ti%"=="" goto :eof
> Line11 if "%LO%"=="" goto :eof
> Line12
> Line13 For /F "tokens=*" %%i in (%PCList%) do (
> Line14 at \\%%i %ti% /interactive "%LO%"
> Line15 if !ErrorLevel!==0 (
> Line16 echo Job scheduled on %%i >> c:\logs\batch.log
> Line17 ) else (
> Line18 echo An error occurred when scheduling the task on %%i >>
> c:\logs\batch.log
> Line19 )
> Line20 )
> Line21
> Line22 endlocal
>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      17th May 2006
- Test the batch file from a Command Prompt before
scheduling it.
- Check the Task Scheduler log file.


"mattr2110" <(E-Mail Removed)> wrote in message
news978B44C-F508-4C85-A983-(E-Mail Removed)...
> OK tried it, it schedules the job but nothing in the log file. I'm not

sure
> why?
>
> "Pegasus (MVP)" wrote:
>
> >
> > "mattr2110" <(E-Mail Removed)> wrote in message
> > news:5E60A022-CC87-4CCD-9A3F-(E-Mail Removed)...
> > > I've created a batch file that will schedule a task on a list of

> > computers.
> > > I'v tried to add an error log that will report if there where any

errors.
> > It
> > > alwasys reports the same error even if it fails. I'm not sure if I

have
> > the
> > > error handling setup correct please help.
> > >
> > > Here is the code
> > > @Echo off
> > > cd\
> > >
> > > cls
> > >
> > > Set /P Ti=Enter the time you wish job to run:
> > > Set /p LO=Enter the location of script or program to run:
> > >
> > > ::1. Configure the path to the PS input list
> > > Set PCList=c:\it\pc.txt
> > >
> > > For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call :Remote)
> > >
> > > GOTO :EOF
> > >
> > > :remote
> > >
> > > at \\%Node% %ti% /interactive "%LO%"
> > >
> > >
> > > if not errorlevel 1 goto end
> > > echo An error occurred during
> > > :end
> > > echo Job completed: %node% >> c:\logs\batch.log
> > >
> > >

> >
> > You have to enable delayed expansion so that %Node% gets
> > set the way it should. You must also ensure that your log directory
> > exists. Try this variant:
> >
> > Line1 @Echo off
> > Line2 setlocal EnableDelayedExpansion
> > Line3
> > Line4 ::1. Configure the path to the PS input list
> > Line5 Set PCList=c:\it\pc.txt
> > Line6 if not exist c:\logs md c:\logs
> > Line7
> > Line8 Set /P Ti=Enter the time you wish job to run:
> > Line9 Set /p LO=Enter the location of script or program to run:
> > Line10 if "%Ti%"=="" goto :eof
> > Line11 if "%LO%"=="" goto :eof
> > Line12
> > Line13 For /F "tokens=*" %%i in (%PCList%) do (
> > Line14 at \\%%i %ti% /interactive "%LO%"
> > Line15 if !ErrorLevel!==0 (
> > Line16 echo Job scheduled on %%i >> c:\logs\batch.log
> > Line17 ) else (
> > Line18 echo An error occurred when scheduling the task on %%i >>
> > c:\logs\batch.log
> > Line19 )
> > Line20 )
> > Line21
> > Line22 endlocal
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?bWF0dHIyMTEw?=
Guest
Posts: n/a
 
      17th May 2006
Task Scheduler log did not help. Like I said the batch file is working (the
job gets scheduled) but nothing is is being logged to the log file that I'm
trying to report errors to (>> c:\it\pcinfo\batch.log).

"Pegasus (MVP)" wrote:

> - Test the batch file from a Command Prompt before
> scheduling it.
> - Check the Task Scheduler log file.
>
>
> "mattr2110" <(E-Mail Removed)> wrote in message
> news978B44C-F508-4C85-A983-(E-Mail Removed)...
> > OK tried it, it schedules the job but nothing in the log file. I'm not

> sure
> > why?
> >
> > "Pegasus (MVP)" wrote:
> >
> > >
> > > "mattr2110" <(E-Mail Removed)> wrote in message
> > > news:5E60A022-CC87-4CCD-9A3F-(E-Mail Removed)...
> > > > I've created a batch file that will schedule a task on a list of
> > > computers.
> > > > I'v tried to add an error log that will report if there where any

> errors.
> > > It
> > > > alwasys reports the same error even if it fails. I'm not sure if I

> have
> > > the
> > > > error handling setup correct please help.
> > > >
> > > > Here is the code
> > > > @Echo off
> > > > cd\
> > > >
> > > > cls
> > > >
> > > > Set /P Ti=Enter the time you wish job to run:
> > > > Set /p LO=Enter the location of script or program to run:
> > > >
> > > > ::1. Configure the path to the PS input list
> > > > Set PCList=c:\it\pc.txt
> > > >
> > > > For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call :Remote)
> > > >
> > > > GOTO :EOF
> > > >
> > > > :remote
> > > >
> > > > at \\%Node% %ti% /interactive "%LO%"
> > > >
> > > >
> > > > if not errorlevel 1 goto end
> > > > echo An error occurred during
> > > > :end
> > > > echo Job completed: %node% >> c:\logs\batch.log
> > > >
> > > >
> > >
> > > You have to enable delayed expansion so that %Node% gets
> > > set the way it should. You must also ensure that your log directory
> > > exists. Try this variant:
> > >
> > > Line1 @Echo off
> > > Line2 setlocal EnableDelayedExpansion
> > > Line3
> > > Line4 ::1. Configure the path to the PS input list
> > > Line5 Set PCList=c:\it\pc.txt
> > > Line6 if not exist c:\logs md c:\logs
> > > Line7
> > > Line8 Set /P Ti=Enter the time you wish job to run:
> > > Line9 Set /p LO=Enter the location of script or program to run:
> > > Line10 if "%Ti%"=="" goto :eof
> > > Line11 if "%LO%"=="" goto :eof
> > > Line12
> > > Line13 For /F "tokens=*" %%i in (%PCList%) do (
> > > Line14 at \\%%i %ti% /interactive "%LO%"
> > > Line15 if !ErrorLevel!==0 (
> > > Line16 echo Job scheduled on %%i >> c:\logs\batch.log
> > > Line17 ) else (
> > > Line18 echo An error occurred when scheduling the task on %%i >>
> > > c:\logs\batch.log
> > > Line19 )
> > > Line20 )
> > > Line21
> > > Line22 endlocal
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      17th May 2006
This can happen for a number of reasons:
- The folder c:\it\pcinfo does not exist
- c:\it\pcinfo\batch.log is a folder
- The task does not have sufficient access rights to the log file

Run the job under the ***command prompt*** and under
the ***same account*** as you scheduled it. This will
immediately show you the cause of the problem!


"mattr2110" <(E-Mail Removed)> wrote in message
news:87687F0E-0760-4799-8FB5-(E-Mail Removed)...
> Task Scheduler log did not help. Like I said the batch file is working

(the
> job gets scheduled) but nothing is is being logged to the log file that

I'm
> trying to report errors to (>> c:\it\pcinfo\batch.log).
>
> "Pegasus (MVP)" wrote:
>
> > - Test the batch file from a Command Prompt before
> > scheduling it.
> > - Check the Task Scheduler log file.
> >
> >
> > "mattr2110" <(E-Mail Removed)> wrote in message
> > news978B44C-F508-4C85-A983-(E-Mail Removed)...
> > > OK tried it, it schedules the job but nothing in the log file. I'm

not
> > sure
> > > why?
> > >
> > > "Pegasus (MVP)" wrote:
> > >
> > > >
> > > > "mattr2110" <(E-Mail Removed)> wrote in message
> > > > news:5E60A022-CC87-4CCD-9A3F-(E-Mail Removed)...
> > > > > I've created a batch file that will schedule a task on a list of
> > > > computers.
> > > > > I'v tried to add an error log that will report if there where any

> > errors.
> > > > It
> > > > > alwasys reports the same error even if it fails. I'm not sure if

I
> > have
> > > > the
> > > > > error handling setup correct please help.
> > > > >
> > > > > Here is the code
> > > > > @Echo off
> > > > > cd\
> > > > >
> > > > > cls
> > > > >
> > > > > Set /P Ti=Enter the time you wish job to run:
> > > > > Set /p LO=Enter the location of script or program to run:
> > > > >
> > > > > ::1. Configure the path to the PS input list
> > > > > Set PCList=c:\it\pc.txt
> > > > >
> > > > > For /F "tokens=*" %%i in (%PCList%) do (Set Node=%%i) & (Call

:Remote)
> > > > >
> > > > > GOTO :EOF
> > > > >
> > > > > :remote
> > > > >
> > > > > at \\%Node% %ti% /interactive "%LO%"
> > > > >
> > > > >
> > > > > if not errorlevel 1 goto end
> > > > > echo An error occurred during
> > > > > :end
> > > > > echo Job completed: %node% >> c:\logs\batch.log
> > > > >
> > > > >
> > > >
> > > > You have to enable delayed expansion so that %Node% gets
> > > > set the way it should. You must also ensure that your log directory
> > > > exists. Try this variant:
> > > >
> > > > Line1 @Echo off
> > > > Line2 setlocal EnableDelayedExpansion
> > > > Line3
> > > > Line4 ::1. Configure the path to the PS input list
> > > > Line5 Set PCList=c:\it\pc.txt
> > > > Line6 if not exist c:\logs md c:\logs
> > > > Line7
> > > > Line8 Set /P Ti=Enter the time you wish job to run:
> > > > Line9 Set /p LO=Enter the location of script or program to run:
> > > > Line10 if "%Ti%"=="" goto :eof
> > > > Line11 if "%LO%"=="" goto :eof
> > > > Line12
> > > > Line13 For /F "tokens=*" %%i in (%PCList%) do (
> > > > Line14 at \\%%i %ti% /interactive "%LO%"
> > > > Line15 if !ErrorLevel!==0 (
> > > > Line16 echo Job scheduled on %%i >> c:\logs\batch.log
> > > > Line17 ) else (
> > > > Line18 echo An error occurred when scheduling the task on %%i >>
> > > > c:\logs\batch.log
> > > > Line19 )
> > > > Line20 )
> > > > Line21
> > > > Line22 endlocal
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?bWF0dHIyMTEw?=
Guest
Posts: n/a
 
      18th May 2006
The folder c:\it\pcinfo does exist
c:\it\pcinfo\batch.log is not a folder

I ran the batch file under the command prompt and it keeps repeating
Enter the time you wish job to run:
Enter the location of script or program to run:

Why does it run differently from the command prompt? Still clueless as to
why nothing is in the log file.

Here is how the script looks

@Echo off
setlocal EnableDelayedExpansion

::1. Configure the path to the PS input list
Set PCList=c:\it\pc.txt

Set /P Ti=Enter the time you wish job to run:
Set /p LO=Enter the location of script or program to run:
if "%Ti%"=="" goto :eof
if "%LO%"=="" goto :eof

For /F "tokens=*" %%i in (%PCList%) do at \\%%i %ti% /interactive "%LO%"

if !ErrorLevel!==0 (
echo Job scheduled on %%i >> c:\it\pcinfo\batch.log
) else (
echo An error occurred when scheduling the task on %%i >>
c:\it\pcinfo\batch.log
)
)

endlocal


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      18th May 2006
You probably called your batch file at.bat. Bad, bad idea!


"mattr2110" <(E-Mail Removed)> wrote in message
news:C9E613A7-2301-4B18-AAC7-(E-Mail Removed)...
> The folder c:\it\pcinfo does exist
> c:\it\pcinfo\batch.log is not a folder
>
> I ran the batch file under the command prompt and it keeps repeating
> Enter the time you wish job to run:
> Enter the location of script or program to run:
>
> Why does it run differently from the command prompt? Still clueless as to
> why nothing is in the log file.
>
> Here is how the script looks
>
> @Echo off
> setlocal EnableDelayedExpansion
>
> ::1. Configure the path to the PS input list
> Set PCList=c:\it\pc.txt
>
> Set /P Ti=Enter the time you wish job to run:
> Set /p LO=Enter the location of script or program to run:
> if "%Ti%"=="" goto :eof
> if "%LO%"=="" goto :eof
>
> For /F "tokens=*" %%i in (%PCList%) do at \\%%i %ti% /interactive "%LO%"
>
> if !ErrorLevel!==0 (
> echo Job scheduled on %%i >> c:\it\pcinfo\batch.log
> ) else (
> echo An error occurred when scheduling the task on %%i >>
> c:\it\pcinfo\batch.log
> )
> )
>
> endlocal
>
>



 
Reply With Quote
 
=?Utf-8?B?bWF0dHIyMTEw?=
Guest
Posts: n/a
 
      18th May 2006
Ok now it runs from the command prompt. The first PC in the txt file
scheduled put the second one returns network path not found.

Still nothing logged in the log file??
 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      18th May 2006

"mattr2110" <(E-Mail Removed)> wrote in message
news:0FCD29F8-9D93-4127-8121-(E-Mail Removed)...
> Ok now it runs from the command prompt. The first PC in the txt file
> scheduled put the second one returns network path not found.
>
> Still nothing logged in the log file??


You need to start with something really, really simple, then
build up from it as you see how it works. It is very hard
for me to work out what you might be up to - the looping
problem, for example, was a very, very long shot!

Create the batch file c:\Test1.bat and place these lines inside:
@echo off
echo %date% %time% >> c:\test1.txt

Use the Task Scheduler to run this batch file, then examine
the file c:\test1.txt. I fully expect it to show a date/time
stamp.

Now modify ***one thing at a time** and keep testing
it until you are back at your own batch file. If you do
this carefully and test it consistently then you will find
out where you go wrong.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Reporting erros in batch files to the Event Log urs@prismanet.ch Windows XP General 1 22nd Feb 2006 01:21 PM
Reporting erros in batch files to the Event Log urs@prismanet.ch Windows XP General 5 17th Feb 2006 11:24 AM
batch file error LuDean Marvin Windows XP General 1 9th Sep 2004 08:48 PM
Error in file size reporting =?Utf-8?B?YnVzaHdpY2s=?= Windows XP Performance 0 16th Dec 2003 08:31 PM
Batch file under XP error Steve Bratsberg Windows XP Help 0 23rd Oct 2003 02:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:30 AM.