Solved

Scheduled task file save

Posted on 2006-11-20
29
184 Views
Last Modified: 2010-04-18
i run a scheduled task that exports a log file each time it runs.  the problem is that if i don't change the name of the log file each time the log info is appended to the existing file so i have info from various days in the same file.  i want to save the file each day with a date stamp in the file name so it will be easier for me to keep up with them and so i will have a "clean" log file each day.  the switch i use in my command line to export the log file is:

/log=c:\oe.log

so everyday when the program runs the log file is saved:

c:\oe.log

what do i need to do so that the file will save like this:

c:\oe20061120.log
0
Comment
Question by:scottspivey
  • 16
  • 13
29 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 17979265
Try this...

/log=c:\oe%date:~-4,4%%date:~0,2%%date:~3,2%.log
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979618
sirbounty,

when i added your suggestion in the switch it stopped writing to the log file altogether.

scott
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17979752
Hmm - alright - do this from a command prompt:

echo %date%
Then try this:

echo %date:~-4,4%%date:~0,2%%date:~3,2%

post the results please.
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979786
echo %date%
Mon 11/20/2006

echo %date:~-4,4%%date:~0,2%%date:~3,2%
2006Mo 1
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17979799
Ah - ok...some dates show the day, some don't...
Adjust the line above to:

/log=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979831
when i entere that the log file did not write again.  so i did a echo in command prompt and here are the results:

2006%date~4,2%%date~7,2%
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979847
no wait typo on my part in the command line.  let me fix that and i will post again
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979882
ok i have fixed the typo but the log file still does not write when i use your switch.  here is what i have that works:

"C:\Program Files\Offline Explorer Pro\OE.exe" /log=c:\oe.log "Commonwealth Core/0" /Minimize /CloseNoCountdown

this runs the profram and the log file writes to c:\oe.log.  when i added your suggestion i have this:

"C:\Program Files\Offline Explorer Pro\OE.exe" /log=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log "Commonwealth Core/0" /Minimize /CloseNoCountdown

the program runs correctly but the log file does not get written.  do i need brackets or something around the date portion of the file name?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17979921
Hmm - not sure, is it echoing the string like you want now?
with
echo %date:~-4,4%%date:~4,2%%date:~7,2%

If that's working, it may be a limitation of the program, perhaps.

If you've scripted this, try assigning the above to a variable first:

output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
"C:\Program Files\Offline Explorer Pro\OE.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown

0
 
LVL 1

Author Comment

by:scottspivey
ID: 17979945
echo of %date:~-4,4%%date:~4,2%%date:~7,2% returns 20061120 which is what i want.

i am running this from the task scheduler in windows so i don't know if i can assign a variable like you suggest.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980017
You could alter the schtasks to 'call' a batch file - not a problem, but hmm...let me think about this a bit - it should work.
Hope you don't mind troubleshooting it...

Try this:

C:\Program Files\Offline Explorer Pro\OE.exe" /log=c:\oe%date:~-4,4%.log "Commonwealth Core/0" /Minimize /CloseNoCountdown

If that fails, let's try doubling up on the %'s...
C:\Program Files\Offline Explorer Pro\OE.exe" /log=c:\oe%%date:~-4,4%%.log "Commonwealth Core/0" /Minimize /CloseNoCountdown

Post back...
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980196
the results from both of those create a file called oe%date and oe%%date respectively.  neither of the files has an extension and neither of them have any data in them.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980238
Are you running these tests from a command line?

What does
output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
echo %output%
give you?

If that works, what does this give you?
"C:\Program Files\Offline Explorer Pro\OE.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980258
i am changing the "run" portion of my scheduled task each time and running it that way.  i can run from a command line and see if i get any different results.  will that make a difference?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 67

Expert Comment

by:sirbounty
ID: 17980298
Possibly...

And we can always convert this to a batch file if you'd rather...might be easier...
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980339
when i run:

output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
echo %output%

from the command line i get an error message telling me that windows can't find:

output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log

i ran "C:\Program Files\Offline Explorer Pro\OE.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown from a comman line and the program runs but i don't get a log file in the output.

i may be easier to run this from a batch file then trying to figure out what is going on.  i have emailed the developer of the program i am running to see if there are some limitations to naming the log file in his program that i need to be aware of but i haven't heard back from him yet.
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980379
i just got a response from the developer and he suggested this:

"C:\Program Files\Offline Explorer Pro\OE.exe" "/log=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log" "Commonwealth Core/0" /Minimize /CloseNoCountdown

that doesn't work either.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17980391
Okay, then let's create a batch script:

::start copying code here
@echo off
set output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
start "c:\program files\offline explorer pro\oe.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown
::end code copy

Name the file Whatever.cmd
Then, schedule Whatever.cmd to run when you need.
You 'may' need to schedule it by passing it through a command prompt...
Instead of C:\PathToFile\Whatever.cmd
you may need the task to read
cmd /c C:\PathToFile\Whatever.cmd

Obviously, change Whatever to read what you need it to...
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980399
No, I wouldn't have suspected the quotes to change anything...
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980471
so my batch script should have this:

@echo off
set output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
start "c:\program files\offline explorer pro\oe.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown

i saved the file to U:\NetworkFolder\OEPProjects\OEP.cmd

to run it from the command prompt i should type:

cmd /c  U:\NetworkFolder\OEPProjects\OEP.cmd

is all of that correct?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980507
Appears to be, yes.

How are you sheduling it?
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980541
i haven't scheduled it yet.  i thought i would wait until the batch file ran correctly from the comman line before i scheduled it.
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980626
ok when i run this through a comman line nothing happens.  i get a quick flash of a command prompt window but the program does not run.  here is what i entered in the command line:

cmd /c  U:\NetworkFolder\OEPProjects\OEP.cmd

here is what i have in my batch script file:

@echo off
set output=c:\oe%date:~-4,4%%date:~4,2%%date:~7,2%.log
start "c:\program files\offline explorer pro\oe.exe" /log=%output% "Commonwealth Core/0" /Minimize /CloseNoCountdown
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980661
Sorry, for the 'test' run - no need to preceed it with cmd /c, just run the cmd...

U:\NetworkFolder\OEPProjects\OEP.cmd
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980682
i did that too to see if it would make a difference and i get the same results.  a quick flash of a command prompt window but no program run and no log file is created.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980690
Hmm - okay, then remove the start from that last line
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980698
k
0
 
LVL 1

Author Comment

by:scottspivey
ID: 17980713
EUREKA!!!!!!

that works.  the project runs, the log file is created and we have only the most recent log info in the file.

thx for sticking this out even though it did not prove to be as simple as i thought it would.

thx.

scott
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17980726
Glad to hear it - thanx for the grade...sorry it took so long - haha. :^)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now