Λlisue's blog

つれづれなるままに更新されないブログ

コマンドの終了をメールで通知するソフト作った

notify

どうも、こんなソフト作ってる場合じゃないけど気がついたら作ってた有末です。

とか使えばいいのでしょうが、欲しいのと少し違ったので自前で作りました。 以下のようにインストールします。

$ pip install notify

インストール後、notify とタイプして設定を行います。 ちなみに下記のようにすると送信にGmailを使用します(パスワードは keyring に保存されるので比較的安心)

##################################################
#                                                #
#              notify setup wizard               #
#                                                #
##################################################

Note: square bracket enclosed text indicate the current value

1. Please enter mail user agent host address [localhost]
> smtp.gmail.com     
2. Please enter mail user agent port number [25]
|
| The following port numbers are usually used.
| - 25  : A default SMTP port
| - 465 : A default SMTP over SSL port
| - 587 : A default submission port
|
> 587
3. Please enter an email address for 'from' [notify@localhost]
> **********@gmail.com
4. Please enter an email address for 'to' [******@gmail.com]
> **********@gmail.com
5. Please enter an email subject [Notify: %(prog)s has %(status)s]
|
| The following special string are available.
| - %(prog)s   : A program name executed.
| - %(status)s : A exit status of executed.
|
> 
6. Please enter an email encoding [utf-8]
> 
7. Please enter an username for authentication []
|
| To remove username, input 'REMOVE'
|
> ***********@gmail.com
8. Please enter an password for authentication []
|
| To remove password, input 'REMOVE'
|
> 

設定が終わった後は簡単です。notify コマンド とすると実行終了後に

  • 実行したコマンド
  • 終了ステータス
  • 実行開始時間
  • 実行終了時間
  • かかった時間(Time)
  • かかった時間(Clock)
  • コマンドの出力

をメールしてきます。便利です。

送ってくるメールの例(--check で送ってくるメール)
一部文字列は隠して有ります。


Success: cat /home/*****/.config/notify/notify.cfg

Start: 2014-01-19 03:20:02.260101
End:   2014-01-19 03:20:02.262953
Time:  0.00285005569458 sec
Clock: 0.0 sec

Output:

[smtp]
host = *****
port = 25

[mail]
from_addr = *****
to_addr = *****
subject = Notify: %(prog)s has %(status)s
encoding = utf-8

[auth]
username =