通知/记录上传失败到txt文件



我在本地服务器上有一个批处理文件,它将文件从不同的文件夹上传到云存储,我想知道我如何能想出一个脚本,每当一个特定的文件从一个特定的文件夹失败或不上传(如果可能的话),或者如果它可以通知我,我将一个条目记录到一个文本文件,所以我可以手动推送失败的文件自己。

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

环顾四周,我被告知我可以使用PowerShell脚本,但我从来没有真正使用过它,所以我不知道从哪里开始,如果有任何其他选项,请让我知道。

假设aws应用程序抛出一个错误,用一个批处理文件来附加错误,类似于:

aws s3 sync q:xxxCase s3://xxx/xxx/Case 2>> C:examplefilename.txt

在PowerShell中你可以使用try/catch语句

try {
aws s3 sync q:xxxCase s3://xxx/xxx/Case
} catch {
$error[0] | out-file C:examplefilename.txt -append
}

或者如果你想要一个错误的电子邮件通知,它会像这样:

try {
aws s3 sync q:xxxCase 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
}

最新更新