Link to home
Create AccountLog in
Avatar of VJ1980
VJ1980

asked on

How to fetch the files automatically using batch files

Hi All,

I am generating pal reports using a batch file. below is the batch file script:
D:
cd "D:\Pal\SQL006"
Powershell .\PAL.ps1 -Log 'D:\Pal\SQL006\sys_Logs_000220.csv' -ThresholdFile 'D:\Pal\SQL006\SQLServer.xml' -Interval 'AUTO' -IsOutputHtml $True -HtmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp]_[GUID].htm' -IsOutputXml $False -XmlOutputFileName '[LogFileName]_PAL_ANALYSIS_[DateTimeStamp]_[GUID].xml' -AllCounterStats $False -OutputDir 'D:\Pal Reports\DECEMBER\26-12-2010\SQL006' -NumberOfProcessors 8 -ThreeGBSwitch $False -SixtyFourBit $True -TotalMemory 32

Open in new window

Every day the threshold file will be changed for example today the log file for 27th December will be sys_Logs_000220.csv & the log file for 28th December is sys_Logs_000221.csv. I need a batch file which will automatically fetch the previous day log. Is there any way to crack it?

Thanks
VJ
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

hi need some clarification as still difficult to understand.

1/ Do you want the script to generate the sys_Logs_000220.csv  , 'D:\Pal Reports\DECEMBER\26-12-2010\SQL006'  portions for you ?  ie update script for the current day ?

2/ Or do you want to copy the resulting log files to a new location ?

3/ How does the 000220 relate to the 26.Dec.2010 or is it just a sequence number that you want to keep track of ?   A better sequence number may be 20101220 as this is easy to construct and makes log files easy to find by date.
See this link...

https://www.experts-exchange.com/questions/21316459/Get-Yesterday-date-in-MS-DOS-Batch-file.html

You can use a similar logic to create the file name.

I however see one challenge....

27th's log file is sys_Logs_000220.csv and
28th's is sys_Logs_000221.csv

so basically sys_Logs_0002 is constant and you are subtracting 7 from 27 to get the 20 or 7 from 28 to get 21. However this logic will fail for dates which are in the first week...

Sid
@sid

The log numbers are sequential.  There is no numerical relationship that would allow you to calculate a date from the number.
You could use VBS (and probably batch too) to check the DateCreated property of the file, and find yesterday's file.....

Rob.
strFolder = "D:\Pal\SQL006\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
dteYesterday = DateAdd("d", -1, Date)
For Each objFile In objFSO.GetFolder(strFolder).Files
	dteFileDate = CDate(Day(objFile.DateCreated) & "/" & MonthName(Month(objFile.DateCreated), True) & "/" & Year(objFile.DateCreated))
	If dteFileDate = dteYesterday Then strFileName = objFile.Path
Next
MsgBox strFileName

Open in new window

@Rob

I'm not sure that the create date is guaranteed to be the date that corresponds to the log data.
No, I guess not, without clarification, but if this process ran on a schedule once a day, then that could be safely assumed...
aikimark:
@sid

The log numbers are sequential.  There is no numerical relationship that would allow you to calculate a date from the number.

If what you say is correct then there has to be some other relation between current date and the name of the logfile... Only OP can confirm, I guess... We will wait for the OP's reply...

Sid
ASKER CERTIFIED SOLUTION
Avatar of VJ1980
VJ1980

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of VJ1980
VJ1980

ASKER

Solution found on the own