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.
>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
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
That is an option, but I think there is a batch file method.
Andy
What method is that?
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)
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.
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.
Thanks a lot Todd.
It works perfect.
Andy