繁体   English   中英

Bash:为bash脚本配置电子邮件提供程序

[英]Bash : Configuring email-provider for bash-script

我正在编写一个脚本,以在我们的Debian服务器( Debian 3.2.68-1+deb7u5 x86_64 GNU/Linux )上运行,它将监视我们拥有的特定端口以及何时在该端口或该端口上没有进程运行可用,那么我将不得不发送电子邮件。 我打算每15分钟运行一次脚本,然后发送一封电子邮件。

我们有一个电子邮件服务器,我想在脚本中添加它的配置,但是我不确定该怎么做。

在Java中,我以这种方式使用配置:

Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "EMAIL-HOST-NAME");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.port", "PORT-PROVIDED");

目前,我的脚本如下,也欢迎您提出任何有关脚本的建议。 谢谢。

#!/bin/bash

server=0.0.0.0 // localhost
port=PORT-NUMBER

  if nc $server $port &> /dev/null; then
       // do nothing
    else
       // send email 
  fi

谢谢。

mailxsendmail都可以从CLI发送完整的电子邮件。 大多数系统均已预装。

“ mailx”的示例:

echo "This is the message body and contains the message" | mailx -v \
-r "someone@example.com" \
-s "This is the subject" \
-S smtp="mail.example.com:587" \
-S smtp-use-starttls \
-S smtp-auth=login \
-S smtp-auth-user="someone@example.com" \
-S smtp-auth-password="abc123" \
-S ssl-verify=ignore \
yourfriend@gmail.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM