Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Notify/Log无法上载到txt文件_Windows_Powershell_Amazon Web Services_Cmd - Fatal编程技术网

Windows Notify/Log无法上载到txt文件

Windows Notify/Log无法上载到txt文件,windows,powershell,amazon-web-services,cmd,Windows,Powershell,Amazon Web Services,Cmd,我的本地服务器上有一个批处理文件,可以将不同文件夹中的文件上传到云存储中。我想知道,当特定文件夹中的特定文件出现故障或无法上传时,或者如果可能,或者如果可以通知我,我如何编写一个脚本,在文本文件中记录条目,所以我可以自己手动推送失败的文件 批处理文件脚本转到aws s3 sync q:\xxx\Case s3://xxx/xxx/Case 环顾四周,我被告知我可以使用PowerShell脚本,但我从未实际使用过它,因此我不知道从何处开始,如果有任何其他选项,请告诉我。假设aws应用程序抛出错误,

我的本地服务器上有一个批处理文件,可以将不同文件夹中的文件上传到云存储中。我想知道,当特定文件夹中的特定文件出现故障或无法上传时,或者如果可能,或者如果可以通知我,我如何编写一个脚本,在文本文件中记录条目,所以我可以自己手动推送失败的文件

批处理文件脚本转到aws s3 sync q:\xxx\Case s3://xxx/xxx/Case


环顾四周,我被告知我可以使用PowerShell脚本,但我从未实际使用过它,因此我不知道从何处开始,如果有任何其他选项,请告诉我。

假设aws应用程序抛出错误,并使用批处理文件仅附加错误,类似于:

aws s3 sync q:\xxx\Case s3://xxx/xxx/Case 2>> C:\examplefilename.txt
使用PowerShell,您可以使用try/catch语句

try {
aws s3 sync q:\xxx\Case s3://xxx/xxx/Case
} catch {
$error[0] | out-file C:\examplefilename.txt -append
}
或者,如果您希望收到有关错误的电子邮件通知,它将是这样的:

try {
aws s3 sync q:\xxx\Case s3://xxx/xxx/Case
} catch {
send-mailmessage -to example@example.org -from script@example.org -body $error[0] -subject "AWS Error" -smtpserver yourmailserver@example.org
}

如果您已经使用了批处理,不要通过添加另一个工具使事情复杂化,只需在批处理中添加几行,以便在发生错误时写入某个文件;取决于批处理的复杂性,可以是函数,也可以是简单的2&1>日志文件;对于通知,我建议使用一些脚本作为计划任务,解析日志文件以查找错误,并在发生错误时发送电子邮件。@Vairis感谢您的帮助,我如何在脚本中创建此函数?我对我目前试图理解的整个批处理文件过程是新手。