2014-05-08 29 views
-1

我是批量腳本新手,所以期待專業人士的幫助。需要一個巴赫腳本歸檔舊文件通過壓縮

我有E:\TIBCO\Spotfire Web Player\6.0.0\Logfiles with Spotfire.Dxp.Web.*.*文件和
E:\TIBCO\Automation Services\6.0.0\LogFiles with Spotfire.Dxp.Automation.*.*文件

,我需要

1. move (copy & delete) all the files that are with Spotfire.Dxp.*.*.* (ex Spotfire.Dxp.*.1.*) from the above paths to E:\TIBCO\logsArchival\rotatedDir 
2. zip all the files that are older than 60 from E:\TIBCO\logsArchival\rotatedDir to E:\TIBCO\logsArchival\ArchiveDir 
3. delete the zip files that are older than 120 days from E:\TIBCO\logsArchival\ArchiveDir 

all the above steps need to be written to the logs. 

我有一個從命令提示符下工作,但如果所謂的從調度的經紀人打電話SafTT不工作PowerShell腳本。邏輯需要寫入批處理腳本。

 $sysname=$env:COMPUTERNAME 
    $Date = Get-Date 
    $Now = Get-Date -format yyyy-MM-dd-HH-mm-ss 
    $host_date=$sysname +"_"+ $Now 

    $RotateDays = "60" 
    $ArchiveDays="120" 
    $ProjectLogsDir = "E:\TIBCO\*\6.0.0\Logfiles" 
    $RotatedLogsDir = "E:\TIBCO\logsArchival\rotatedDir" 
    $ArchivedLogsDir= "E:\TIBCO\logsArchival\archiveDir" 
    $psLogsDir= "E:\TIBCO\logsArchival\shLogsDir" 

    $LastRotate = $Date.AddDays(-$RotateDays) 
    $LastArchive = $Date.AddDays(-$ArchiveDays) 

    $RenameLogFiles = Get-Childitem $ProjectLogsDir -include Spotfire.Dxp.*.*.* -exclude spotfire.Dxp.web.KeepAlive.* -Recurse 
    $RenameLogFiles 
    $RenameLogFiles | Where-Object {!$_.PSIsContainer} | Rename-Item -NewName { $host_date +"_"+ $_.Name.Replace(' ','_') }; 

    $RotatedLogFiles = Get-Childitem $ProjectLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse 
    $RotatedLogFiles 
    $RotatedLogFiles | move-item -destination "$RotatedLogsDir" 

    $ZippedLogFiles = Get-Childitem $RotatedLogsDir -include *_Spotfire.Dxp.*.*.* -Recurse | Where {$_.LastWriteTime -le "$LastRotate"} 
    $ZippedLogFiles 
    Zip $ArchivedLogsDir\$host_date.zip -j $ZippedLogFiles 
    $ZippedLogFiles | Remove-Item -Force 

    $DeleteZippedFiles = Get-Childitem $ArchivedLogsDir\*.zip -Recurse | Where {$_.LastWriteTime -le "$LastArchive"} 
    $DeleteZippedFiles 
    $DeleteZippedFiles | Remove-Item -Force 

    $DeletePsFiles = Get-Childitem $psLogsDir\*.log -Recurse | Where {$_.LastWriteTime -le "$LastRotate"} 
    $DeletePsFiles 
    $DeletePsFiles | Remove-Item -Force 
+0

向我們展示您的努力或特定問題,我們將很樂意爲您提供幫助 –

+0

您是否有任何限制*必須使用標準Windows軟件*來完成? – cup

+0

是的。我有一個Powershell腳本,其中包含了從命令提示符工作的壓縮文件,但在調用名爲SafTT的調度程序代理程序中調用時嘗試在批處理腳本中調用該壓縮文件時無法工作。 – user1658369

回答

1

使用批處理文件,並在其中使用powershell命令和正在工作的腳本。

+0

實際上,我們正在從.cmd文件調用.ps1腳本,但它不起作用。 – user1658369

+0

什麼是錯誤信息?你的批處理文件是什麼樣的?嘗試使用您的憑據作爲測試來執行批處理文件 - 也許該腳本沒有網絡訪問權限,批處理腳本也會出現同樣的問題。 – foxidrive

+0

它不會給出任何錯誤。期望執行所有其他步驟的壓縮 – user1658369

相關問題