Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > "at" scheduled job not working

Reply
Thread Tools Display Modes

"at" scheduled job not working

 
 
John A Grandy
Guest
Posts: n/a

 
      08-21-2008
Windows Server 2003 R2 SP2

I created a scheduled job with that "at" command that runs every morning at
2:00 AM :

"cmd /c C:\MyFolder\MyBatFile.bat"

In Scheduled Tasks , I see this job listed and "Next Run Time" and "Last Run
Time" are always correct ( every morning , they have advanced 1 day ).
"Last Result" is always 0x0

However, nothing is accomplished by the job.

When I run MyBatFile.bat manually it works fine.

Could there be security issus ? How to diagnose why the .bat file doesn't
work when run as a scheduled job ?

What other options are available for scheduling this .bat file ?


 
Reply With Quote
 
 
 
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      08-21-2008

"John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
news:...
> Windows Server 2003 R2 SP2
>
> I created a scheduled job with that "at" command that runs every morning
> at 2:00 AM :
>
> "cmd /c C:\MyFolder\MyBatFile.bat"
>
> In Scheduled Tasks , I see this job listed and "Next Run Time" and "Last
> Run Time" are always correct ( every morning , they have advanced 1 day ).
> "Last Result" is always 0x0
>
> However, nothing is accomplished by the job.
>
> When I run MyBatFile.bat manually it works fine.
>
> Could there be security issus ? How to diagnose why the .bat file doesn't
> work when run as a scheduled job ?
>
> What other options are available for scheduling this .bat file ?


A couple of comments:
- You don't need to invoke a separate command processor.
Launching MyBatFile.bat will suffice.
- Make the first line in your batch file like so:
echo %date% %time% >> c:\test.txt

Now run the job again under at.exe and report the contents of
c:\test.txt. Next, post the full contents of MyBatFile.bat.


 
Reply With Quote
 
John A Grandy
Guest
Posts: n/a

 
      08-22-2008
Ok, I re-configured the scheduled job, losing the "cmd /c" , and adding the
logging of the timestamp to the .bat file :

at 17:07 /every:M,T,W,Th,F,S,Su "C:\svn_repository\svn-backup.bat"

The log file was created and contains : Thu 08/21/2008 17:07:00.05

So ... at least the first line of the .bat file was run.

However, none of the other lines were run.

Here is the contents of the .bat file :

echo %date% %time% >> c:\svn_repository\svn-backup.log

c:\python25\python.exe c:\svn_repository\hot-backup.py --archive-type=zip
c:\svn_repository\myrepository c:\svn-backup



Thu 08/21/2008 17:07:00.05
"Pegasus (MVP)" <> wrote in message
news:...
>
> "John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
> news:...
>> Windows Server 2003 R2 SP2
>>
>> I created a scheduled job with that "at" command that runs every morning
>> at 2:00 AM :
>>
>> "cmd /c C:\MyFolder\MyBatFile.bat"
>>
>> In Scheduled Tasks , I see this job listed and "Next Run Time" and "Last
>> Run Time" are always correct ( every morning , they have advanced 1
>> day ). "Last Result" is always 0x0
>>
>> However, nothing is accomplished by the job.
>>
>> When I run MyBatFile.bat manually it works fine.
>>
>> Could there be security issus ? How to diagnose why the .bat file
>> doesn't work when run as a scheduled job ?
>>
>> What other options are available for scheduling this .bat file ?

>
> A couple of comments:
> - You don't need to invoke a separate command processor.
> Launching MyBatFile.bat will suffice.
> - Make the first line in your batch file like so:
> echo %date% %time% >> c:\test.txt
>
> Now run the job again under at.exe and report the contents of
> c:\test.txt. Next, post the full contents of MyBatFile.bat.
>
>



 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a

 
      08-22-2008
I suspected all along that the scheduled job ran, in spite of
you thinking that it did not. You now claim that only the first
line runs. You have to change your way of thinking: In a batch
file ALL lines run until you hit an error. You must add further
logging code in order do see what's going on, e.g. like so:

@echo off
set Log=c:\svn_repository\svn-backup.log
echo %date% %time% >> %Log%
echo User=%UserName% %path% >> %Log%
c:\python25\python.exe
c:\svn_repository\hot-backup.py
--archive-type=zip c:\svn_repository\myrepository
c:\svn-backup 1>>%Log% 2>>&1

You will probably see that the account you use has no access
rights to one of the resources in your command. This raises the
question: Why do you use at.exe to schedule the job? Such jobs
will run under the System account. Why not use the inbuilt Task
Scheduler? It lets you specify the account to use!


"John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
news:OYwMu5%...
> Ok, I re-configured the scheduled job, losing the "cmd /c" , and adding
> the logging of the timestamp to the .bat file :
>
> at 17:07 /every:M,T,W,Th,F,S,Su "C:\svn_repository\svn-backup.bat"
>
> The log file was created and contains : Thu 08/21/2008 17:07:00.05
>
> So ... at least the first line of the .bat file was run.
>
> However, none of the other lines were run.
>
> Here is the contents of the .bat file :
>
> echo %date% %time% >> c:\svn_repository\svn-backup.log
>
> c:\python25\python.exe c:\svn_repository\hot-backup.py --archive-type=zip
> c:\svn_repository\myrepository c:\svn-backup
>
>
>
> Thu 08/21/2008 17:07:00.05
> "Pegasus (MVP)" <> wrote in message
> news:...
>>
>> "John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
>> news:...
>>> Windows Server 2003 R2 SP2
>>>
>>> I created a scheduled job with that "at" command that runs every morning
>>> at 2:00 AM :
>>>
>>> "cmd /c C:\MyFolder\MyBatFile.bat"
>>>
>>> In Scheduled Tasks , I see this job listed and "Next Run Time" and "Last
>>> Run Time" are always correct ( every morning , they have advanced 1
>>> day ). "Last Result" is always 0x0
>>>
>>> However, nothing is accomplished by the job.
>>>
>>> When I run MyBatFile.bat manually it works fine.
>>>
>>> Could there be security issus ? How to diagnose why the .bat file
>>> doesn't work when run as a scheduled job ?
>>>
>>> What other options are available for scheduling this .bat file ?

>>
>> A couple of comments:
>> - You don't need to invoke a separate command processor.
>> Launching MyBatFile.bat will suffice.
>> - Make the first line in your batch file like so:
>> echo %date% %time% >> c:\test.txt
>>
>> Now run the job again under at.exe and report the contents of
>> c:\test.txt. Next, post the full contents of MyBatFile.bat.
>>
>>

>
>



 
Reply With Quote
 
Al Dunbar
Guest
Posts: n/a

 
      08-22-2008
While debugging these kinds of problems I'd suggest not turning echo off.
Also, it can sometimes be simpler to turn the whole batch into a single
compound command and redirect its output once, i.e.:


@echo off
setlocal enabledelayedexpansion
set Log=c:\svn_repository\svn-backup.log

ECHO ON
(
echo !date! !time!
echo User=!UserName!
echo Path=!path!
c:\python25\python.exe
c:\svn_repository\hot-backup.py --archive-type=zip
echo/errorlevel = !errorlevel!
c:\svn_repository\myrepository c:\svn-backup
echo/errorlevel = !errorlevel!
) 1>>%Log% 2>>&1

The setlocal command and using "!" instead of "%" is required to avoid
problems discussed at length elsethread. You might also consider explicitly
setting the default directory, as this may not be the same when the batch is
run as a scheduled task. To set it to where the batch file is located:

pushd "%~dp0"

If you want the batch file and its log file to be in the same location and
with the same base name, I'd suggest this:

set Log="%~dpn0.log"

Finally, is this: "c:\svn_repository\myrepository" a batch file or an
executable? I generally recommend specifying the file type as .exe, .cmd, or
..bat to avoid any ambiguity.

/Al


"Pegasus (MVP)" <> wrote in message
news:%...
>I suspected all along that the scheduled job ran, in spite of
> you thinking that it did not. You now claim that only the first
> line runs. You have to change your way of thinking: In a batch
> file ALL lines run until you hit an error. You must add further
> logging code in order do see what's going on, e.g. like so:
>
> @echo off
> set Log=c:\svn_repository\svn-backup.log
> echo %date% %time% >> %Log%
> echo User=%UserName% %path% >> %Log%
> c:\python25\python.exe
> c:\svn_repository\hot-backup.py
> --archive-type=zip c:\svn_repository\myrepository
> c:\svn-backup 1>>%Log% 2>>&1
>
> You will probably see that the account you use has no access
> rights to one of the resources in your command. This raises the
> question: Why do you use at.exe to schedule the job? Such jobs
> will run under the System account. Why not use the inbuilt Task
> Scheduler? It lets you specify the account to use!
>
>
> "John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
> news:OYwMu5%...
>> Ok, I re-configured the scheduled job, losing the "cmd /c" , and adding
>> the logging of the timestamp to the .bat file :
>>
>> at 17:07 /every:M,T,W,Th,F,S,Su "C:\svn_repository\svn-backup.bat"
>>
>> The log file was created and contains : Thu 08/21/2008 17:07:00.05
>>
>> So ... at least the first line of the .bat file was run.
>>
>> However, none of the other lines were run.
>>
>> Here is the contents of the .bat file :
>>
>> echo %date% %time% >> c:\svn_repository\svn-backup.log
>>
>> c:\python25\python.exe c:\svn_repository\hot-backup.py --archive-type=zip
>> c:\svn_repository\myrepository c:\svn-backup
>>
>>
>>
>> Thu 08/21/2008 17:07:00.05
>> "Pegasus (MVP)" <> wrote in message
>> news:...
>>>
>>> "John A Grandy" <johnagrandy-at-gmail-dot-com> wrote in message
>>> news:...
>>>> Windows Server 2003 R2 SP2
>>>>
>>>> I created a scheduled job with that "at" command that runs every
>>>> morning at 2:00 AM :
>>>>
>>>> "cmd /c C:\MyFolder\MyBatFile.bat"
>>>>
>>>> In Scheduled Tasks , I see this job listed and "Next Run Time" and
>>>> "Last Run Time" are always correct ( every morning , they have advanced
>>>> 1 day ). "Last Result" is always 0x0
>>>>
>>>> However, nothing is accomplished by the job.
>>>>
>>>> When I run MyBatFile.bat manually it works fine.
>>>>
>>>> Could there be security issus ? How to diagnose why the .bat file
>>>> doesn't work when run as a scheduled job ?
>>>>
>>>> What other options are available for scheduling this .bat file ?
>>>
>>> A couple of comments:
>>> - You don't need to invoke a separate command processor.
>>> Launching MyBatFile.bat will suffice.
>>> - Make the first line in your batch file like so:
>>> echo %date% %time% >> c:\test.txt
>>>
>>> Now run the job again under at.exe and report the contents of
>>> c:\test.txt. Next, post the full contents of MyBatFile.bat.
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Olaf Engelke [MVP]
Guest
Posts: n/a

 
      08-24-2008
Hi John,
John A Grandy wrote:
> Windows Server 2003 R2 SP2
> I created a scheduled job with that "at" command that runs every
> morning at 2:00 AM :

at is outdated and should no longer be used.
As mentioned, it will run in a user context which has not the necessary
rights to access the ressources needed.
Replacement for the AT command is SCHTASKS.exe.
Best greetings from Germany
Olaf

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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
"quicken background agent" / "quicken scheduled updates" blocked in Vista Options markm75 Windows Vista Security 0 06-16-2007 01:10 AM
"quicken background agent" / "quicken scheduled updates" blocked in Vista markm75 Windows Vista General Discussion 4 06-15-2007 03:42 PM
WSUS client does noet "listen" to GPO setting "Re-prompt for restart with scheduled installations" Henno Keers Update Services 0 11-07-2006 09:59 AM
Remote buttons "Guide", "More info" & "Ch+/-" stop working after user switch Rob Mauchel Windows Media Center 1 01-17-2004 04:56 AM
"Save Contact List..." / "Import Contacts from a Saved File..." not working... GMTplusOne Windows MSN Messenger 0 11-28-2003 01:35 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59