1.

Solve : Scheduling a batch file execution?

Answer»

Hello everybody,

I have this batch script, and I want him to be executed on daily basis at 2:15PM
Now, there is always the “Schedule Tasks” of Windows XP (start -> programs -> accessories -> system tools -> scheduled tasks)
But I was told by a friend of mine, that it is not sure that it will work for .bat files 100%

Ruther he suggested, I better make use of AT Command:
Well
I tried working on it, and I got my batch script executed on 2:15PM while stating:
at 2:15PM /interactive C:\Dir1\bat_File.bat

I just want to have it executed everyday in 2:15PM

Does anyone have any idea how can I achieve this?

Moreover, is there any difference if I run the same code on a server (not remotely)

thnx in advance,
PupliTry the /Every: switch.Hi back, and thank you for your asnwer

Yes, I tried using
at 2:15PM /interactive /every:date C:\Dir1\bat_File.bat

but I don't know, why i am not TAKING what I want Quote from: Pupli on February 08, 2010, 06:42:20 AM

"He suggested, I better make use of AT Command."

rem at 2:15PM /interactive /every:date C:\Dir1\bat_File.bat

rem the interactive option will not allow to run a 2AM automaticallly

rem at /?

C:\Dir1>type bat_File.bat
echo Hello at command > c:\Dir1\bat_File.txt

C:\Dir1>

Code: [Select]C:\Dir1>at 9:51am c:\Dir1\bat_File.bat
Added a new job with job ID = 1
C:\Dir1>at
Status ID Day Time Command Line
-------------------------------------------------------------------------------
1 Today 9:51 AM c:\Dir1\bat_File.bat

C:\Dir1>dir
Volume in drive C has no label.
Volume Serial NUMBER is F4A3-D6B3

Directory of C:\Dir1

02/08/2010 09:51 AM .
02/08/2010 09:51 AM ..
02/08/2010 09:49 AM 0 at
02/08/2010 09:48 AM 44 bat_File.bat
02/08/2010 09:51 AM 19 bat_File.txt
02/08/2010 09:49 AM 0 CLS
4 File(s) 63 bytes
2 Dir(s) 300,503,519,232 bytes free

C:\Dir1>type bat_file.txt
Hello at command

C:\Dir1>Quote
rem the interactive option will not allow to run a 2AM automaticallly

Is that supossed to mean that removing the interactive option from
the code, I can have my bat_File.bat executed periodically on
daily basis at 2:15PM by making use of:

Code: [Select]at 2:15PM /every:date C:\Dir1\bat_File.bat


It just doesn't work.
Well, of course ... It really works if I just schedule it at a specific time, but just for today
It will need another "manual" schedulation the next dayI have not had a problem using Schedule Tasks. Why not try it and see if it works for you?

You can read all about the AT command here.

You can use the interactive switch to allow the task to interact with the DESKTOP of the user who is logged on at the time the task runs.

The every switch is used for either days of the month or days of the week (M,T,W,Th,F,S,Su).

Note: jobs put on the schedule by the Scheduler GUI cannot be seen by the AT command. Jobs put on the schedule by the AT command can be seen by the Scheduler GUI.

Good luck. Quote from: Pupli on February 08, 2010, 10:32:19 AM
Code: [Select]at 2:15PM /every:date C:\Dir1\bat_File.bat
http://ss64.com/nt/at.html
AT 23:30 /EVERY:m,t,w,th,f,s,su c:\backups\every_day.cmd
( I have not tested the /EVERY day procedure. brr )

"Rights needed to issue an AT command

By default only a Local Administrator can issue an AT command, a Domain Admin can direct the command at any machine.

To configure an AT job as part of a users login script - the user must be a member of the local Administrators group.

Schedule vs Task Sheduler"

Thank you, to all of you

Finally, I got my job scheduled:
Code: [Select]AT 09:00AM /INTERACTIVE /EVERY:m,t,w,th,f,s,su C:\Dir1\job.bat
Now, I have a final question:
I am loged as a local administrator in my machine, and I scheduled my job,
Now, what does it actually mean:
Quote
Note: jobs put on the schedule by the Scheduler GUI cannot be seen by the AT command. Jobs put on the schedule by the AT command can be seen by the Scheduler GUI.
Is this supposed to mean, that I can see it as a process in task manager?
Quote
Note: jobs put on the schedule by the Scheduler GUI cannot be seen by the AT command. Jobs put on the schedule by the AT command can be seen by the Scheduler GUI.
Is this supposed to mean, that I can see it as a process in task manager?

No. It means if you run the AT command with no parameters, only jobs put on the schedule with the AT command will appear in the list. If you bring up the GUI scheduler (start==accessories==>system tools==>scheduled tasks), you will see tasks scheduled with the AT command and the jobs scheduled manually with the GUI.

You are scheduling a bat file, the task manager will show cmd.exe executing when the job executes, not the name of the batch file. The cmd shell is required for all batch files as it is the interpreter for the batch code.

Quote
I am loged as a local administrator in my machine, and I scheduled my job,
Now, what does it actually mean:

Nothing in particular. The job will get the same permissions that the local administrator has. The local administrator name should show up in the task manager as the user name when the job runs.

Question: why did you use the AT command and not the GUI?

Quote
Question: why did you use the AT command and not the GUI?

Because a friend of mine told me that for jobs that need to be executed just once a day I'd better make use of the AT command. He also told me that I'd be capable to "control" it while it runs. (as I have used some pause commands thruoghout the code

Now, will you allow me to ask you:
What did you think I'll ever prefer the AT commands rather then GUI?
Quote
What did you think I'll ever prefer the AT commands rather then GUI?

Actually I didn't.

Quote
Because a friend of mine told me that for jobs that need to be executed just once a day I'd better make use of the AT command.

Did your friend explain why? Either way is fine. In fact the AT command can be used in a batch file as the target of an if statement where you can schedule a job if a certain condition is TRUE (or false). In any case, they're better than a Windows script where you have to account not only for the time but the offset from GMT.

All,

It would be great if i get a help from anyone to know how to execute a .pl script from batch file.

1. My perl script look for 3 arugment on command line

eg: g:\app\scriipts>abc.pl -Year2009 Month01 -useconfig.cfg

2. I have to make the batch file with the below logic.

Have to cut the year alone from command "date \T"

Have to cut the month from the command "date \T" and need to do -1 from the current month

Please let me know if you need anymore clarifiactions on my request.

Quote from: aarruunnmd on February 10, 2010, 10:42:22 AM
2. I have to make the batch file with the below logic.

Have to cut the year alone from command "date \T"

Have to cut the month from the command "date \T"


C:\batch>type datet.bat

Code: [Select]@echo off
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
echo year=%year%
pause
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%-%month%-%day%
rem echo %TODAY%
echo.
echo.
echo The following commands build the 'date variable' called "TODAY".
echo.
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
echo set TODAY=%%year%%-%%month%%-%%day%%
echo.
echo Now ... TODAY = %TODAY%
echo.
Output:

C:\batch> datet.bat
year=2010
Press any key to continue . . .


The following commands build the 'date variable' called "TODAY".

for /f "tokens=2-4 delims=/ " %a in ('date /T') do set year=%c
for /f "tokens=2-4 delims=/ " %a in ('date /T') do set month=%a
for /f "tokens=2-4 delims=/ " %a in ('date /T') do set day=%b
set TODAY=%year%-%month%-%day%

Now ... TODAY = 2010-02-10


C:\batch>Quote from: aarruunnmd on February 10, 2010, 10:42:22 AM
All,

It would be great if i get a help from anyone to know how to execute a .pl script from batch file.

1. My perl script look for 3 arugment on command line

eg: g:\app\scriipts>abc.pl -Year2009 Month01 -useconfig.cfg

2. I have to make the batch file with the below logic.

Have to cut the year alone from command "date \T"

Have to cut the month from the command "date \T" and need to do -1 from the current month

Please let me know if you need anymore clarifiactions on my request.


if you want to cut this and that from the date command, that means you are trying to getting current time correct? Then do it inside your Perl script since you are already using it! Why do you want to use crappy batch (cmd.exe) for that , especially when it comes to dealing with date !? There are various date modules you can use with Perl for date maths, one of them is DateTime. Some others are Date::Calc etc.



Discussion

No Comment Found