如何编写批处理文件错误/返回的免费通知脚本?

发布于 2024-07-06 07:43:53 字数 424 浏览 10 评论 0原文

我在停止服务并重新启动它时遇到问题,希望在进程运行时收到通知并让我知道结果是什么。

这是场景, 我有一个“sc”命令的文本文件输出。 我想发送该文件,但不是作为附件。 另外,我想快速查看电子邮件主题中的初始状态。

这是“servstop.txt”文件内容:

[SC] StartService 失败 1058:

服务也无法启动 因为它被禁用或者因为它 没有关联的已启用设备 它。

我希望电子邮件的主题为“警报服务启动:[SC] StartService FAILED 1058” 以及包含上面整个错误消息的正文。

我将把我当前的方法放在下面的答案中,使用一个名为 blat 的程序向我发送结果。

I have a problem with stopping a service and starting it again and want to be notified when the process runs and let me know what the result is.

Here's the scenario,
I have a text file output of an "sc" command. I want to send that file but not as an attachment. Also, I want to see the initial status quickly in the subject of the email.

Here's the 'servstop.txt' file contents:

[SC] StartService FAILED 1058:

The service cannot be started, either
because it is disabled or because it
has no enabled devices associated with
it.

I want the subject of the email to be "Alert Service Start: [SC] StartService FAILED 1058"
and the body to contain the entire error message above.

I will put my current method in an answer below using a program called blat to send me the result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就此别过 2024-07-13 07:43:53

我就是这样做的。
首先,我得到 blat 邮件(公共域 smtp 邮件程序)并将其放入 d:\blat 目录中。 我的 Exchange 服务器允许我在没有 ID/密码的情况下发送电子邮件,并且只是假设我是 blat 命令的“发件人”字段中的人。

@echo off
sc start Alerter >servstop.txt
SetLocal EnableDelayedExpansion
set content=
set subj=
for /F "delims=" %%i in (servstop.txt) do set content=!content! %%i  
for /f "tokens=1 delims=:" %%s in ("%content%") do set subj=%%s 

d:\blat\blat.exe -body "%content%" -to [email protected] -f [email protected] -server smtp.foo.bar -s "Alert Service Start:%subj% " -log d:\blat\blat.log
EndLocal

Here's how I'm doing this.
First I got blat mail (public domain smtp mailer) and dropped it into d:\blat directory. My Exchange server allows me to email without id/password and just assumes that I am the person in the 'from' field of the blat command.

@echo off
sc start Alerter >servstop.txt
SetLocal EnableDelayedExpansion
set content=
set subj=
for /F "delims=" %%i in (servstop.txt) do set content=!content! %%i  
for /f "tokens=1 delims=:" %%s in ("%content%") do set subj=%%s 

d:\blat\blat.exe -body "%content%" -to [email protected] -f [email protected] -server smtp.foo.bar -s "Alert Service Start:%subj% " -log d:\blat\blat.log
EndLocal
那片花海 2024-07-13 07:43:53

Splunk 看起来很有前途。 不过还没试过。 下面是来自该网站关于索引和警报的两个块引用。

索引:通过各种灵活的输入方法,您可以索引来自所有应用程序、服务器和网络设备的日志、配置、陷阱和警报、消息、脚本以及代码和性能数据。 监视文件系统的脚本和配置更改、捕获存档文件、查找和追踪实时应用程序日志、连接到网络端口以接收系统日志、SNMP 和其他基于网络的检测。 这只是一切的开始。

警报:任何搜索都可以按计划运行,并根据搜索结果触发通知或操作。 由于 Splunk 可以跨不同的组件和技术工作,因此它是您的工具库中最灵活的监控工具。 通知可以通过电子邮件、RSS 或 SNMP 发送到其他管理控制台。 操作触发脚本执行用户描述的活动,例如重新启动应用程序、服务器或网络设备。

Splunk looks promising. Haven't tried it though. Two blockquotes from the site about index and alert below.

INDEX: With a variety of flexible input methods you can index logs, configurations, traps and alerts, messages, scripts, and code and performance data from all your applications, servers and network devices. Monitor file systems for scripts and configuration changes, capture archive files, find and tail live application logs, connect to network ports to receive syslog, SNMP and other network-based instrumentation. And this is just where it starts.

ALERT: Any search can be run on a schedule and trigger notifications or actions based on the search results. And because it works across different components and technologies, Splunk is the most flexible monitoring tool in your arsenal. Notifications can be sent via email, RSS or SNMP to other management consoles. Actions trigger scripts performing user described activities like restarting an application, server or network device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文