ユーザ用ツール

サイト用ツール


ログとxmlファイルの整理とリネーム1

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
ログとxmlファイルの整理とリネーム1 [2023/04/05 06:41] 98.158.246.3ログとxmlファイルの整理とリネーム1 [2023/04/05 16:28] (現在) – 削除 taatin
行 1: 行 1:
-<code> 
-# .logファイルを取得する 
-$LogFiles = Get-ChildItem -Filter *.log 
- 
-# 各.logファイルに対して処理を行う 
-foreach ($LogFile in $LogFiles) { 
-    # ファイルの内容を取得する 
-    $FileContent = Get-Content $LogFile.FullName 
-    # ホスト名を抽出する 
-    $Hostname = ($FileContent | Select-String -Pattern "set hostname (.*)").Matches.Groups[1].Value 
-    # 日付部分を抽出する 
-    $Date = $LogFile.Name.Substring(0, 8) 
- 
-    # 出力ファイル名を作成する 
-    $OutputFileName = "$Date-$Hostname-run.log" 
-    # 最後のコンフィグの開始行を見つける 
-    $ConfigStart = ($FileContent | Select-String -Pattern "$Hostname\(.*\)# configure" -AllMatches)[-1].LineNumber 
-    # コンフィグの終了行を見つける 
-    $ConfigEnd = ($FileContent[$ConfigStart..($FileContent.Count - 1)] | Select-String -Pattern "$Hostname\(.*\)#" -AllMatches)[0].LineNumber 
-    # 開始行と終了行の間のテキストを抽出し、出力ファイル名で保存する 
-    $FileContent[$ConfigStart-1..($ConfigStart + $ConfigEnd-1)] | Set-Content $OutputFileName 
- 
-    # XMLファイルの処理 
-    $XmlFile = Get-ChildItem -Filter *.xml | Where-Object { (([xml](Get-Content $_.FullName)).SelectSingleNode("//hostname").InnerText) -eq $Hostname } 
-    $XmlOutputFileName = "$Date-$Hostname-run.xml" 
-    # XMLファイル名を変更する 
-    Rename-Item $XmlFile.FullName $XmlOutputFileName 
- 
-    # yyyymmddのフォルダを作成し、ファイルをコピーする 
-    $OutputFolder = New-Item -ItemType Directory -Force -Path $Date 
-    Copy-Item $OutputFileName -Destination $OutputFolder.FullName 
-    Copy-Item $XmlOutputFileName -Destination $OutputFolder.FullName 
-} 
-</code> 
  
ログとxmlファイルの整理とリネーム1.1680676898.txt.gz · 最終更新: 2023/04/05 06:41 by 98.158.246.3

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki