Page 1 of 1
AT command help
Posted: 15 Jan 2010 20:56
by Flyingmetalyak
I'm trying to make a batch file that will perform a command at a specific time. I've been looking around on sites for some help with this, but I haven't been successful at getting it to work. Any help would be greatly appreciated. Also, if this would be of any help I'm trying to get it to perform the command every day. So, a way to stop that would be kinda useful. Thanks
Posted: 18 Jan 2010 13:01
by avery_larry
Well, there's the obvious -- use the task scheduler or AT command.
But if you want to code it yourself using a script, then you'll have to use the %time% variable to compare against a set time you want something to happen:
Code: Select all
@echo off
set timetorun=21:00
:loop
if %time%==%timetorun% goto :process
rem Delay 30 seconds
ping -n 31 -w 999 127.0.0.1
goto :loop
:process
echo Put your commands here to run at the appropriate time.
rem delay 60 seconds to make sure the current time no longer matches
rem the set timetorun
ping -n 61 -w 999 127.0.0.1
goto :loop
The biggest problem with this -- is if there's some slow down or delay for whatever reason, and the if statement that compares the time does NOT happen to run at the correct time -- then the script will just wait until the next day. You can add a lot of code to run the script 1 time AFTER a given time but BEFORE another given time (so a 30 minute window where it runs 1 time) or you can add a variable like "did it run today?".
Posted: 18 Jan 2010 17:25
by adz
Nice solution for this problem.
But I have some questions about it. First an addition, you need to place " before and after the variabels. ("%time%")
But the time is displayed like this: 21:00:00,00
So when the pc compares the 'timetorun' with the real time it isn't the same because the more detailed notation of the pc. How can you avoid this? I tried for example: 21:00:*,*
But i'm kind of new in this more difficult stuff.
Looking forward for your solvation.
greetings out of holland.
Posted: 19 Jan 2010 14:30
by avery_larry
Sorry -- I just threw together something for an idea.
substring manipulation would work:
%time:~0,5% will only use the 1st 5 characters of the %time% variable. Set timetorun appropriately. Test thoroughly.
Posted: 19 Jan 2010 15:17
by adz
Yes that works!!! Great! I changed those little things in first your example and this is the result:
Code: Select all
@echo off
cls
set timetorun=21:00
:loop
if "%time:~0,5%"=="%timetorun%" goto :process
rem Delay for 30 seconds
ping localhost -n 31 >nul
goto loop
:process
start program-of-your-choice.exe
rem delay 60 seconds to make sure the current time no longer matches with the set timetorun
ping localhost -n 61 >nul
goto :loop
Re: AT command help
Posted: 28 Jan 2010 16:14
by Flyingmetalyak
Thanks, this really helps