Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Increment %time% by 1 minute in a bat file???

2,733 views
Skip to first unread message

mik...@excite.com

unread,
Nov 7, 2005, 4:44:43 PM11/7/05
to
Hello

I am writing a batch file which shuts down an Oracle DB (W2K3), but before
the shut down, I would like to cleanly shut off the DTS machine running on
Windows XP. I have an AutoIT script on the DTS which I would like to run
before executing the line which shuts down the DB so I figured I could
utilize the AT command to schedule the remote task. I can not think of a
way to do it except for scheduling the time for the DTS shutdown but I want
to force the shutdown when the power goes out and the UPS batteries are
draining so this would need to be initiated by the bat file on the Oracle
Server which has the last line of shutdown for the 2K3 Box.

What I am finding is that I can use a command like

at \\computername %time% c:\bats\cleanshutdn.exe which would schedule the
task for the next day (just past the current time unfortunately). I need
to somehow increment the variable of time by 1 minute or so so that the
next occurance of the time is within the next minute. I have tried the
following:

set scheduledtime=%time% + 1
set scheduledtime="%time%" + 1

and I keep getting a string variable of scheduledtime which looks like
12:33:00:00+1 or whatever so that if the CURRENT time is 12:33 PM, then teh
at command on the remote machine will occur at 12:34 PM.

Is this possible to add a value to the current time so that I can do a:

at \\computername %scheduledtime% c:\bats\cleanshutdn.exe

TIA
--

Mike

Phil Robyn

unread,
Nov 7, 2005, 7:27:28 PM11/7/05
to

I don't use AT anymore, but this used to work for me (watch out for line
wrap):

- - - - - - - - - - begin screen capture WinXP - - - - - - - - - -
C:\cmd>echo %time%&mysoon debug 60 cmd /c "c:\somepath\somefile.bat some
parms"
16:25:15.02
at 16:26:15 cmd /c "c:\somepath\somefile.bat some parms"

C:\cmd>wyllist test\mysoon.cmd
==========begin file C:\cmd\test\mysoon.cmd ==========
001. @echo off
002. ::
003. :: replacement for SOON.EXE from the Resource Kit
004. ::
005. :: syntax: %0 (seconds) cmd /c "c:\somepath\somefile.bat some parms"
006. ::
007. :: for display only without scheduling:
008. ::
009. :: %0 debug (seconds) cmd /c "c:\somepath\somefile.bat
some parms"
010. ::
011. setlocal
012. set debug=%1
013. set myinput=%*
014. if /i %debug% NEQ debug set "debug="&goto :begin
015. set debug=echo
016. for /f "tokens=1*" %%a in (
017. 'echo %myinput%'
018. ) do set myinput=%%b
019. :begin
020. for /f "tokens=5-7 delims=:. " %%a in (
021. 'echo.^|time^|findstr "current"'
022. ) do (
023. set myhh=%%a&set mymm=1%%b&set myss=1%%c
024. )
025. for /f "tokens=1*" %%a in (
026. 'echo %myinput%'
027. ) do set seconds=%%a&set myinput=%%b
028. set thh=%myhh%X
029. if %thh:~1,1% EQU X (
030. set myhh=10%myhh%
031. ) else (
032. set myhh=1%myhh%
033. )
034. set /a myhh-=100, mymm-=100, myss-=100
035. set /a hh2mm = myhh * 60
036. set /a hh2mm *= 60
037. set /a total_seconds = mymm * 60
038. set /a total_seconds += hh2mm
039. set /a total_seconds += myss
040. set /a target_seconds = total_seconds + seconds
041. set /a S2 = target_seconds %% 86400
042. set /a hours = S2 / 3600
043. set /a minutes = S2 %% 3600
044. set /a tseconds = S2 %% 60
045. set /a minutes /= 60
046.
047. if %hours% LSS 10 set hours=0%hours%
048. if %minutes% LSS 10 set minutes=0%minutes%
049. if %tseconds% LSS 10 set tseconds=0%tseconds%
050. %debug% at %hours%:%minutes%:%tseconds% %myinput%
051. endlocal&goto :EOF
==========end file C:\cmd\test\mysoon.cmd ==========
- - - - - - - - - - end screen capture WinXP - - - - - - - - - -

Ted Davis

unread,
Nov 7, 2005, 9:04:22 PM11/7/05
to
On Mon, 07 Nov 2005 16:44:43 -0500, "mik...@excite.com"
<mik...@excite.com> wrote:

>Hello
>
>I am writing a batch file which shuts down an Oracle DB (W2K3), but before
>the shut down, I would like to cleanly shut off the DTS machine running on
>Windows XP. I have an AutoIT script on the DTS which I would like to run
>before executing the line which shuts down the DB so I figured I could
>utilize the AT command to schedule the remote task. I can not think of a
>way to do it except for scheduling the time for the DTS shutdown but I want
>to force the shutdown when the power goes out and the UPS batteries are
>draining so this would need to be initiated by the bat file on the Oracle
>Server which has the last line of shutdown for the 2K3 Box.
>
>What I am finding is that I can use a command like
>
>at \\computername %time% c:\bats\cleanshutdn.exe which would schedule the
>task for the next day (just past the current time unfortunately). I need
>to somehow increment the variable of time by 1 minute or so so that the
>next occurance of the time is within the next minute. I have tried the
>following:
>
>set scheduledtime=%time% + 1
>set scheduledtime="%time%" + 1
>
>and I keep getting a string variable of scheduledtime which looks like
>12:33:00:00+1 or whatever so that if the CURRENT time is 12:33 PM, then teh
>at command on the remote machine will occur at 12:34 PM.

That's what you are telling the system to do. set /a is used for
arithmetic, but the time is not a number, so no arithmetic can be done
on it as is.


>
>Is this possible to add a value to the current time so that I can do a:
>
>at \\computername %scheduledtime% c:\bats\cleanshutdn.exe

It's possible: split the time into hour, minute, and A/PM segments,
add one to the minute - if that takes it past 59, reset it to zero and
increment the hour - it that goes past 12 reset to one and toggle the
A/PM flag. Then put it all back together.

Or, you could just put a batch wrapper around the command and
incorporate a delay in it (ping -n 59 localhost, or sleep 60 if you
have a sleep utility).

--
T.E.D. (tda...@gearbox.maem.umr.edu)

bayg...@gmail.com

unread,
Nov 7, 2005, 11:10:27 PM11/7/05
to
set scheduledtime="%time%" + 1
should be
set /a scheduledtime=%time% + 1

-BG

billious

unread,
Nov 8, 2005, 12:13:41 AM11/8/05
to

<mik...@excite.com> wrote in message
news:w7ednYKHwoQ...@giganews.com...

[1]@echo off
[2]for /f "tokens=1,2,*delims=: " %%i in ('time/t') do set yhh=24%%i&set
ymm=6%%j&set ysh=%%k
[3]if %yhh% LSS 2400 set /a yhh=2160+%yhh%
[4]set /a ymm=%ymm%+%1
[5]set /a yhh=%yhh%+(%ymm%/60)-10
[6]set /a ymm=100+(%ymm% %% 60)
[7]set /a yhh=100+(%yhh% %% 24)
[8]if not defined ysh set ysh=00:00
[9]echo AT ... %yhh:~1%:%ymm:~1%:%ysh% .....

Each line begins [number]. Lines will be wrapped in transmission and need to
be rejoined. The [number] at the beginning of each line needs to be removed.

Notes:
1. I can't recall whether "time/t" returns h:mm[:ss:hh] or 0h:mm[:ss:hh] for
hours<10. Line [3] takes care of the single-digit situation
2. Requires a parameter (number-of-minutes) and has no protection for
absence of this parameter
3. My "time/t" command returns HH:MM. This routine calculates on the basis
of HH:MM:00:00 in this case. I'd suggest that in line [8], the 00:00 be
changed to 30:00 to allow for the situation where MM is about to change when
the time/t is executed (in the application, AT would then receive a time of
HH:MM+1:00:00, which may well be in the past by then....) Taking out the
"if" clause would MOVE this time to ysh - so 30:00 would set your "AT" time
to half-way through the next minute....
4. The playing with figures is to compensate for the case of HH or MM being
08 or 09 (not-octal crash-potential)
5. Clearing-up of environment variables (yhh,ymm,ysh) is by your preferred
method.

AAMOI, here's the test routine I used

[1]@echo off
[2]for /f "tokens=1,2,*delims=: " %%i in (tlist.txt) do echo %%i - %%j - %%k
&set yhh=24%%i&set ymm=6%%j&set ysh=%%k&call :process %1
[3]goto :eof
[4]:process
[5]if %yhh% LSS 2400 set /a yhh=2160+%yhh%
[6]set /a ymm=%ymm%+%1
[7]set /a yhh=%yhh%+(%ymm%/60)-10
[8]set /a ymm=100+(%ymm% %% 60)
[9]set /a yhh=100+(%yhh% %% 24)
[10]if not defined ysh set ysh=00:00
[11]echo %yhh:~1%:%ymm:~1%:%ysh%

and test data:

12:33:00:00
01:59:59:99
1:59:59:99
23:59:59:99
23:09:09:99
12:33
01:59
23:59
23:09
1:59
09:59:59:99
9:59:59:99

HTH

...Bill


Timo Salmi

unread,
Nov 8, 2005, 12:45:42 AM11/8/05
to
One option. The same VBS-aided script method should work as for the
date as in

31} How many days ago was 31.12.2003? What date was it 100 days ago?
143047 Oct 30 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Ted Davis

unread,
Nov 8, 2005, 8:49:33 AM11/8/05
to

Why? That doesn't make the TIME string into a number, so it still
doesn't work, only now SET throws an error message and sets the
variable to a very wrong value: just the hour element.

--
T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.

mik...@excite.com

unread,
Nov 8, 2005, 9:12:31 AM11/8/05
to
billious wrote:

Cool, I think this is going to work. Thanks for the help.

--
mik...@excite.com

mik...@excite.com

unread,
Nov 8, 2005, 9:14:25 AM11/8/05
to
Ted Davis wrote:
>
> It's possible: split the time into hour, minute, and A/PM segments,
> add one to the minute - if that takes it past 59, reset it to zero and
> increment the hour - it that goes past 12 reset to one and toggle the
> A/PM flag. Then put it all back together.
>
> Or, you could just put a batch wrapper around the command and
> incorporate a delay in it (ping -n 59 localhost, or sleep 60 if you
> have a sleep utility).

Yep, I think sleeping for an extra minute if mm=59 would be simplest. There
is no real rush and an extra minute won't kill me in this case.

Thanks

--
mik...@excite.com

Reinhardt Kern

unread,
Nov 8, 2005, 3:11:06 PM11/8/05
to
"mik...@excite.com" <mik...@excite.com> wrote:

>Hello
>
>I am writing a batch file which shuts down an Oracle DB (W2K3), but before
>the shut down, I would like to cleanly shut off the DTS machine running on
>Windows XP. I have an AutoIT script on the DTS which I would like to run
>before executing the line which shuts down the DB so I figured I could
>utilize the AT command to schedule the remote task. I can not think of a
>way to do it except for scheduling the time for the DTS shutdown but I want
>to force the shutdown when the power goes out and the UPS batteries are
>draining so this would need to be initiated by the bat file on the Oracle
>Server which has the last line of shutdown for the 2K3 Box.
>

Hi Mike,

are you allowed to use external commands?
Download "psexec" from www.sysinternals.com
Assuming you have admin access to the DTS machine, you can start
your shutdown script in this way:
psexec \\computer cmd /c c:\batches\shutdown_DTS.cmd

or even more simple using psshutdown:
psshutdown -r -f -t 3 \\computer

(with -r = Reboot machine, -f force shutdown )

or kill the DTC-process
pskill \\computer DTC-Process

Reinhardt

mik...@excite.com

unread,
Nov 9, 2005, 9:35:36 AM11/9/05
to
Reinhardt Kern wrote:


> Hi Mike,
>
> are you allowed to use external commands?
> Download "psexec" from www.sysinternals.com

Hey, that made thigns REALLY simple. Thanks for the tip. sysinternals
saved me again. I am a huge fan of BGInfo, I have been leaving my
customized mark on workstations and servers whereever I support. :-)

Thanks

Mike

> Assuming you have admin access to the DTS machine, you can start
> your shutdown script in this way:
> psexec \\computer cmd /c c:\batches\shutdown_DTS.cmd
>
> or even more simple using psshutdown:
> psshutdown -r -f -t 3 \\computer
>
> (with -r = Reboot machine, -f force shutdown )
>
> or kill the DTC-process
> pskill \\computer DTC-Process
>
> Reinhardt

--
mik...@excite.com

Dr John Stockton

unread,
Nov 9, 2005, 8:34:25 AM11/9/05
to
JRS: In article <dkpe26$pn8$1...@haavi.uwasa.fi>, dated Tue, 8 Nov 2005
05:45:42, seen in news:alt.msdos.batch.nt, Timo Salmi <t...@uwasa.fi>
posted :

>One option. The same VBS-aided script method should work as for the
>date as in
>
> 31} How many days ago was 31.12.2003? What date was it 100 days ago?
> 143047 Oct 30 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
> tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

DATE2NUM, quoted in that, does *not* give the Julian date number. The
latter changes, by definition, at noon GMT. What it gives is the
Chronological Julian Date Number, which changes at midnight local time
(or at midnight of whatever sort of time its parameters refer to). Its
internal Help does have Chronological.

Those who prefer not to import executables should be able to do the
conversions without difficulty by implementing in NT-class script an
algorithm derived from Zeller, as in <URL:http://www.merlyn.demon.co.uk/
daycount.htm>.

If the OP is willing to import,
NOWMINUS m-1 f2 r
will give him the time a minute ahead of local "now" as hh:mm:ss
(without the dubious :cc at the end). NOWMINUS (via sig line 3) can
also be used to add to a given hh:mm:ss, or to add 61 seconds if a
minute is not quite enough.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Timo Salmi

unread,
Nov 11, 2005, 2:26:39 AM11/11/05
to
Dr John Stockton wrote:
Timo Salmi <t...@uwasa.fi> posted :

>>31} How many days ago was 31.12.2003? What date was it 100 days ago?
>>143047 Oct 30 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>>tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

> DATE2NUM, quoted in that, does *not* give the Julian date number. The
> latter changes, by definition, at noon GMT. What it gives is the

Thanks John. Reference to your posting included for the next update.
I appreciate the "fine print", even if the actual script tasks work
well enough as is. So the Google reference will suffice.

0 new messages