Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to automate a daily log, but the command to save the log has the date and time in it. I need to find a way to have the script update portions of itself with the curent date.
ex.
Dslogread –s yyyymmddhhmmss –e yyyymmddhhmmss
dslogread -s 20090415060000 -e 20090416060000The command views the log which I will be capturing for a 24 hour period from 6 am to 6 am.
I would also be using a changing date reference in the saving of the file, but once I can get the script to manipulate the command, the file saving part would be easy.

I did find out a trick by creating a .txt file with .LOG in the first line that will have the current time adn date in the .txt file each time you open it. I just need to be able to reference that in the script.... Unless there's an easier way with in a VBscript.

Ok, I had a chance to search some more and found the Now$ and Date$ variables.
How would you go about reformating those into the format within the command. The month and day needs to be two digit also.
Dslogread –s yyyymmddhhmmss –e yyyymmddhhmmss

d=year(date)*10000+month(date)*100+day(date)
t=hour(time)*10000+minute(time)*100+second(time)
wsh.echo d & t

Hey that works great... almost!
I can get this output:
dslogread -s 4/16/2009060000 -e 20090417060000 -N 6Using this code:
d=year(date)*10000+month(date)*100+day(date)
y = DateAdd("d", -1,(date))
oShell.SendKeys "dslogread -s "
oShell.SendKeys y &"060000 -e "
oShell.SendKeys d &"060000 -N 6"Now I just need to get the "/"s out. I tried:
y = DateAdd("d", -1,year(date)*10000+month(date)*100+day(date))
But get an error.

Success!
d=year(date)*10000+month(date)*100+day(date)
y=year(date)*10000+month(date)*100+day(date)-1
oShell.SendKeys "dslogread -s "
oShell.SendKeys y &"060000 -e "
oShell.SendKeys d &"060000 -N 6"Thanks for the point in the right direction!

y=year(date)*10000+month(date)*100+day(date)-1
!!!! bug 1/1/2009 1/2/2009y=year(date-1)*10000+month(date-1)*100+day(date-1)

Ahhh, glad I checked back in. Thanks for catching my bug!
One last question. When I save these files, I try to emulate the current naming format with is:
Node_YY_MM_DD(-1).txt
or
024_09_04_16.txt <--yesterday's dateHaving trouble finding a way to use underscore separators and use yesterday's date. The date formats that I have seen so far don't allow for this type of format.
Any ideas?

This is what I have.
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe"
WScript.Sleep 500
y= year(date-1)*10000+month(date-1)*100+day(date-1)
oShell.SendKeys "024_"
oShell.SendKeys y &".txt"
And it outputs:
024_20090416.txtIt's close, but there are other scripts looking for the file logs to parse data out of these logs, and the file name nees to be in the correct format those other scripts are looking for.
I kinda inherited these other scripts and I don't really want to go tinkering with them.

today date:
d=array(year(date),right("0"&month(date),2),right("0"&day(date),2))
wsh.echo join(d,"_")or
d=year(date)&"_"&right("0"&month(date),2)&"_"&right("0"&day(date),2)
wsh.echo d

Almost there, just need yesterday's day in this and i'm golden!
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe"
WScript.Sleep 500p= right("0" & day(date()),2) 'Gives two-digit day of month.
m= right("0" & month(date()),2) 'Gives two-digit month.
y= right("" & year(date()),2) 'Gives four digit year.oShell.SendKeys "024_" & y &"_" & m &"_" & p &".txt"

actually, i just figured out the right spot for the -1 to give yesterday's date and it works like this:
set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe"
WScript.Sleep 500p= right("0" & day(date()-1),2) 'Gives two-digit day of month.
m= right("0" & month(date()-1),2) 'Gives two-digit month.
y= right("" & year(date()-1),2) 'Gives two-digit year.oShell.SendKeys "024_" & y &"_" & m &"_" & p &".txt"

You might want to try this
Dim fileDate
Dim FileTime
Dim dtYesterday
dtYesterday = DateAdd( "d", -1, Date() )
FileDate = (Year(dtYesterday)*100+ Month(dtYesterday) )*100 + Day(dtYesterday)
Filetime = (Hour(Now)*100+Minute(Now))

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |