2017-03-14 11 views
1

[-s filename]オプションを指定してファイルを監視し、そのファイルがデータを取得したときに適切な情報をメールで送信します。私はサイトを検索し、いくつかのオプションを思いついたが、私のためにクリックしなかった。ファイルを監視し、 `mail`コマンドで電子メールを送信したい場合

私は単純に "メール"をテストするために次のことを試みています。私もmailxを試しました。ユーザーはメールを受信せず、提供される出力はmailmailxの場合とまったく同じです。

最終的に、元のbashスクリプトをmailまたはmailxコマンドで編集して、動作させることができると仮定します。

これは私がやっていることであり、入力すると コマンドラインが返ってきます。

ありがとうございました。ありがとうございました。私は本当に感謝しています。


[[email protected] ~]$ echo "TEST" | mail -s subject [email protected] 

[[email protected] ~]$ send-mail: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol 
send-mail: warning: inet_protocols: configuring for IPv4 support only 
postdrop: warning: inet_protocols: IPv6 support is disabled: Address family not supported by protocol 
postdrop: warning: inet_protocols: configuring for IPv4 support only 
+0

このような別のスクリプトから推奨事項付き。ありがとうございました!それのために – Dimos

+0

Tnks。以下の答えは、始めるのに最適な場所のようです。それはあなたのために働くのですか?もしそうでなければ、sendmailが動作しない理由を調べる必要があります。多くの理由があります。その場合は、http://unix.stackexchange.comで投稿することをお勧めします。幸いです。 – shellter

+0

驚くばかり!私は同意する、その素晴らしい出発点。ありがとうございました。 現時点では私は仕事用ネットワーク上にいるので、SMTP_SERVERの設定方法や設定についてはわかりません。 – Dimos

答えて

2

あなたは(おそらくCLOSE_WRITE?)後にしているイベントにinotifywaitを使用することをお勧め。

メーラーをSMTPサーバーで構成し、可能であれば(必要に応じて)いくつかの資格情報を構成する必要があります。

私は通常、次のスクリプトで、heirloom-mailxパッケージからmailxを使用します。

#!/bin/false 

function send_email { 
    # args are: subject [to] [from_name] [from_address] 
    # subject is required 
    # to and from_* are optional, defaults below 

    # stdin takes the message body... don't forget 

    # this function uses mailx from heirloom-mailx 

    local SMTP_SRVR="${YOUR_SERVER}" 
    local SMTP_USER="${YOUR_USERNAME}" 
    local SMTP_PASS="${YOUR_PASSWORD}" 

    local DEFAULT_TO="${YOUR_RECIPIENT}" 
    local DEFAULT_FROM_NAME="${YOUR_SENDER_NAME}" 
    local DEFAULT_FROM_ADDR="${YOUR_SENDER_EMAIL}" 

    if [ $# -lt 1 ]; then 
    echo "${FUNCNAME}(): missing subject (arg 1)..." >&2 
    return 1 
    fi 
    local SUBJECT="$1" 
    shift 

    if [ $# -lt 1 ]; then 
    local TO="${DEFAULT_TO}" 
    else 
    local TO="$1" 
    shift 
    fi 

    if [ $# -lt 1 ]; then 
    local FROM="${DEFAULT_FROM_NAME}" 
    else 
    local FROM="$1" 
    shift 
    fi 

    if [ $# -lt 1 ]; then 
    FROM="${FROM} <${DEFAULT_FROM_ADDR}>" 
    else 
    FROM="${FROM} <$1>" 
    shift 
    fi 

    mailx -s"${SUBJECT}" -r"${FROM}" -Ssmtp="${SMTP_SRVR}" -Ssmtp-auth-user="${SMTP_USER}" -Ssmtp-auth-password="${SMTP_PASS}" "${TO}" 
    return $? 
} 

あなたはその後、(例えば:my_send_email.inc)上記を使用することができます更新

#!/bin/bash 

source my_send_email.inc 

echo "Testing" | send_email "${MY_EMAIL}" 
関連する問題