• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Scheduled task file save

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
scottspivey
Asked:
scottspivey
  • 16
  • 13
1 Solution
 
sirbountyCommented:
Try this...

/log=c:\oe%date:~-4,4%%date:~0,2%%date:~3,2%.log
0
 
scottspiveyAuthor Commented:
sirbounty,

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

scott
0
 
sirbountyCommented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
scottspiveyAuthor Commented:
echo %date%
Mon 11/20/2006

echo %date:~-4,4%%date:~0,2%%date:~3,2%
2006Mo 1
0
 
sirbountyCommented:
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
 
scottspiveyAuthor Commented:
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
 
scottspiveyAuthor Commented:
no wait typo on my part in the command line.  let me fix that and i will post again
0
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
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
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
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
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
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
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
Possibly...

And we can always convert this to a batch file if you'd rather...might be easier...
0
 
scottspiveyAuthor Commented:
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
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
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
 
sirbountyCommented:
No, I wouldn't have suspected the quotes to change anything...
0
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
Appears to be, yes.

How are you sheduling it?
0
 
scottspiveyAuthor Commented:
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
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
Sorry, for the 'test' run - no need to preceed it with cmd /c, just run the cmd...

U:\NetworkFolder\OEPProjects\OEP.cmd
0
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
Hmm - okay, then remove the start from that last line
0
 
scottspiveyAuthor Commented:
k
0
 
scottspiveyAuthor Commented:
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
 
sirbountyCommented:
Glad to hear it - thanx for the grade...sorry it took so long - haha. :^)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 16
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now