当我们在ZIP文件中出现错误时,我的下面脚本会生成错误日志。 Zip文件应该是三个文件的cosnsist,如果有任何一个缺少run.bat抛出一个Error.log文件。 我故意在ZIP中创建一个丢失的文件,脚本应该生成一个error.log,但脚本抛出Error.log文件为空。 当我尝试使用断点时,脚本正在正常工作并因为出现错误而收到邮件,如果我取消断点并运行它将不会发送邮件。脚本有什么问题。感谢您的支持。
$errorlog = "D:\EmailConnector-Disc Optimus\logs\error.log"
$emailconnecter_log = "D:\EmailConnector-Disc Optimus\logs\connector.log"
#1 print "Running email bat file...... \n";
Write-Host "Running email bat file...... \n"
$prog="cmd.exe"
$params=@('/C','"D:\EmailConnector-Disc Optimus\run.bat"','connector.log')
start-process $prog $params -WorkingDirectory "D:\EmailConnector-Disc Optimus" -RedirectStandardOutput $emailconnecter_log
#$rc = & D:\EmailConnector-Disc Optimus\run.bat > $emailconnecter_log
if (-not $?)
{
Write-Host $rc
$status = "running Daily email bat file failed on $hostname"
Del_Daily
Del_Dat
Send_Mail
exit
}
else
{
Write-Host $rc
Write-Host "Email send sucess fully....."
}
###check for email error log
If (Test-Path $errorlog)
{
$content = Get-Content $errorlog
Write-Host "File is not blank"
Write-Host "File is not blank"
foreach ($line in $content)
{
Write-Host $line
IF ($line | Select-String -Quiet -Pattern '^\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\sERROR')
{
Write-Host $line "Done"
$status = "Daily Email Connector Has ERRORS in the log."
$body = "Check $hostname\logs or $archive_location "
Write-Host $status `n $body
# Send_Mail
$rc = Copy-Item $errorlog $archive_location
$rc = Copy-Item $emailconnecter_log $archive_location
Del_Daily
Del_Dat
exit
}
else{Write-Host "No Error message"}
}
}
else{Write-Host "File is blank"}