簡體   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