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

Run a batch file only once per day

1,102 views
Skip to first unread message

Andy

unread,
Aug 10, 2009, 10:11:34 PM8/10/09
to
I am looking for help with 2 batch files.

1. I am looking to see if there is a way to run a batch file only once
per day.
Preferably without using any outside utilities.

(The batch files copies files to a backup directory.)

2. I also have some log files that only allow appending for a fixed
amount of time.
Ex.

I would like C:\WINDOWS\tracing\PPP.log and
ModemLog_SoftV92 Data Fax Modem.txt to be copied and renamed to a
format like [current time].txt.

I would only want that to be done after a modem connection has been
terminated.

I think this will do the copying and renaming part.

for /f "tokens=1-5 delims=/ " %%d in ("%date%") do copy "test.txt" %%e-
%%f-%%g.txt

Thanks.


foxidrive

unread,
Aug 10, 2009, 11:09:21 PM8/10/09
to
On Mon, 10 Aug 2009 19:11:34 -0700 (PDT), Andy
<chocolate...@yahoo.com> wrote:

>I am looking for help with 2 batch files.
>
>1. I am looking to see if there is a way to run a batch file only once
>per day.
> Preferably without using any outside utilities.
>
>(The batch files copies files to a backup directory.)

Use the task scheduler, or the command line version AT.EXE

Carsten Beckermann

unread,
Aug 11, 2009, 7:55:01 AM8/11/09
to

"foxidrive" <got...@woohoo.invalid> schrieb im Newsbeitrag news:g4o185141bq8jm3ga...@4ax.com...

Hello

foxidrive have had a good idea with the AT.EXE.

I don't have found the information about Your Operation System.
The fact, that You have choosen the newsgroup alt.msdos.batch and not the one alt.msdos.batch.nt isn't a pointer for me to specify
Your OS.

If Your OS is Windows XP, then I can help You with the command SCHTASKS (it's XP-build in, no download or installation necessary i
think as You prefer). I don't know if it's existing in Win2000 or earlier NT-clones.

I have had an big journey into the user profile runas problematic with the simple AT.EXE command of XP. It's running the commands as
SYSTEM. For a copy-action it's enough i think. But running specific programs won't work for me with that.

Is a wrote, the alternative SCHTASKS have done a good job for me. Maybe i can help someone with that information _before_ the
user-profile-problems occur.

I use that one:
========================================
schtasks /create /SC EINMAL /TR d:\backup\batch.bat /TN One-Time-Batch-Today /ST 08:00:00 /RU administrator /RP adminpassword
========================================

The term "EINMAL" is german language and means ONCE. For Your problem You have to change that to DAILY or somewhat. The command
SCHTASKS uses language-specific terms i found out.

But creating the task by hand is easier, i think. You have to create the task one single time for every day working.

My commandline above have a variable in the starttime (i changed this here before posting for easier understanding) which is given
from the batch. I will post the part of my batch if someone ask it.


Thank You so far
Greetings
Carsten

Andy

unread,
Aug 11, 2009, 10:14:40 AM8/11/09
to
On Aug 10, 10:09 pm, foxidrive <got...@woohoo.invalid> wrote:
> On Mon, 10 Aug 2009 19:11:34 -0700 (PDT), Andy
>
> <chocolatemint77...@yahoo.com> wrote:
> >I am looking for help with 2 batch files.
>
> >1. I am looking to see if there is a way to run a batch file only once
> >per day.
> >    Preferably without using any outside utilities.
>
> >(The batch files copies files to a backup directory.)
>
> Use the task scheduler, or the command line version AT.EXE

That is an option, but I think there is a batch file method.

Andy

Larry__Weiss

unread,
Aug 11, 2009, 10:39:50 AM8/11/09
to
Andy wrote:
> On Aug 10, 10:09 pm, foxidrive <got...@woohoo.invalid> wrote:
>> On Mon, 10 Aug 2009 19:11:34 -0700 (PDT), Andy
>> <chocolatemint77...@yahoo.com> wrote:
>>> I am looking for help with 2 batch files.
>>> 1. I am looking to see if there is a way to run a batch file only once
>>> per day.
>>> Preferably without using any outside utilities.
>>
>> Use the task scheduler, or the command line version AT.EXE
>
> That is an option, but I think there is a batch file method.
>

What method is that?

Message has been deleted

Todd Vargo

unread,
Aug 11, 2009, 5:09:53 PM8/11/09
to
Jawade wrote:
>
> Maybe this:
>
> @echo off
> :start
> echo.|time|find "02:00:00.">nul
> if errorlevel 1 goto :start

Not a very good method. Date/time format issues aside, this will only allow
the batch to continue at exactly 02:00:00. The computer may or may not be
running at that time but more importantly, depending on how much activity is
going on at that time, it may be missed altogether. It also consumes a lot
of resources to run any batch in a continuous loop.

A better method is to store the current date and run the batch. When the
batch tries to run again, it compares the stored date to current and reacts
accordingly. There are numerous methods to store a date. Separate file, same
batch or registry but just as OP has not mentioned which OS this is for, we
also don't know where a safe place to store the date is on that system.

I will respond separately to OP's post to ask for more details.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

Todd Vargo

unread,
Aug 11, 2009, 5:15:13 PM8/11/09
to
Andy wrote:
> I am looking for help with 2 batch files.
>
> 1. I am looking to see if there is a way to run a batch file only once
> per day.
> Preferably without using any outside utilities.
>
> (The batch files copies files to a backup directory.)

You will have to be more specific. What OS is this for? Do you intend for
the batch to load at boot time and remain running until the computer is shut
down? If so, will it be running longer than a day? Should the batch run at a
specific time of day? Where a safe place to store the date is on your
system? (file or registry?) Is there a specific reason you don't want to Use
the task scheduler? Have you written any code? Show us what you have tried
so far.

Todd Vargo

unread,
Aug 11, 2009, 5:58:59 PM8/11/09
to
Andy wrote:
> On Aug 11, 1:39 pm, "Pegasus" <I....@fly.com.oz> wrote:
>>
>> Presumably you're launching your backup file at startup/logon time,
>> and presumably you do not wish to back up your files at subsequent
>> logons. If so then you could use this batch file:
>> @echo off
>> set Semaphore=%temp%\Semaphore.txt
>> if not exist "%Semaphore%" goto Action
>> for %%a in ("%Semaphore%") do set FDate=%%~ta
>> for /F "tokens=1,2" %%a in ('echo %FDate%') do (
>> if "%%a %%b"=="%date%" goto :eof
>> )
>>
>>> Action
>> echo %date% %time% > "%Semaphore%"
>> echo Backing up files
>>
>> The above code works if %date% resolves to DOW Date.
>
> I tried the code and it echos Backing up files whenever it is run.
> I would like to only run once per day.
>
> The semaphore files contained the day of the week Tue as the first 3
> characters.

Try this modification. If it still does not work, change the location of the
semaphore file to some location other than %TEMP% folder.

@echo off
set Semaphore=%temp%\Semaphore.bat
if not exist "%Semaphore%" goto Action
call "%Semaphore%"
if "%lastrun%" equ "%date%" (
echo %~nx0 already ran once today.
pause
goto :eof
)

:Action
echo set lastrun=%date%>"%Semaphore%"
echo Backing up files

BTW, please don't multipost.

Andy

unread,
Aug 12, 2009, 9:19:30 AM8/12/09
to

Thanks a lot Todd.

It works perfect.

Andy

0 new messages