hyperv 发表于 2018-9-2 14:03:57

powershell提取日志内容

写了一个powershell提取日志内容的脚本,搜索oracle关于ORA的报错信息  

  

  
#查找结果赋值
  
$d=Get-ChildItemc:\test-Recurse | where{"script.txt"}
  

  

  
#判断文件是否存在,若不存在返回3
  

  
if ($d -eq $null)
  
{
  

  
   write-host " ALERT FILE NO FOUND"
  
   write-host " check your directory wether file exsits"
  

  
   $ERROR= {return 3;}
  

  
}
  

  

  
else
  

  
{
  

  

  
#过滤oracle警告日志文件ORA-错误
  

  
$c=Get-Content c:\test\script.txt | select-string -pattern "ora-" | Select-Object -last 3
  

  
#判断ORA-错误存在条件
  
#若$c返回值为null,则输出1返回值结束循环
  

  
    if ( $c -eq$null )
  

  
    {
  
      write-host "STATE:OK"
  

  

  
      $OK= {return 1;}
  

  
    }
  
#若$c返回值不为空,则复制oracle警告日志,清空原警告日志,返回0结束循环
  

  
    else
  
    {
  
            copy c:\test\script.txtc:\test\scriptbak.txt
  

  

  
            write-host "STATE:ERROR"
  
            write-host "$c"
  

  

  
            " " > c:\test\script.txt
  

  
            $CRITICAL= {return 0;}
  

  

  
    }
  

  
}


页: [1]
查看完整版本: powershell提取日志内容