Slightlyの日々精進ナリ
プロフィール

Author:slightly
なんちゃってSEのSlightlyです。
とりえあず備忘録として使えるように少しずつUPしていきます。
人に見せるようなものではないけど。。。
というか事実、誰もみないんだけどね(笑)。



最近の記事



最近のコメント



最近のトラックバック



月別アーカイブ



カテゴリー



リンク



友達申請フォーム

この人と友達になる



ブログ内検索



リンク

このブログをリンクに追加する



++++++ PR ++++++



SMTPD alive checker by expect
expect による SMTPD の死活監視設定。

これは 25 番ポートの監視なので実際のデーモンチェックとはいかないかも。


-------------------------------------------------
# don't echo the dialog
log_user 0

spawn telnet localhost 25
expect {
"Connected to" {}
default {
# try to restart
# use catch so we don't report errors on the exec,
# only on the dialog itself
catch {exec /etc/rc.d/init.d/sendmail restart >&/dev/null} result
sleep 5
# redo test, fail if get an error again
spawn telnet localhost 25
expect {
"Connected to" {}
default {
flush stdout;
exit 1;
}
}
}
}

expect {
"220 " {}
default { # fail if we're not greeted properly
flush stdout;
exit 2;
}
}

send "QUIT\r"
expect {
"221 " {}
default { # fail if we're not ack-ed properly
flush stdout;
exit 3;
}
}

flush stdout;
exit 0;
-------------------------------------------------



HTTPD alive checker by expect
expect による HTTPD の死活監視設定。


expect -f httpd.exp

[httpd.expの内容]

------------------------------------------
# expect による http サーバプロセス監視、再起動
# don't echo the dialog
log_user 0

spawn telnet localhost 80
expect {
"Connected to" {}
default {
# try to restart
# use catch so we don't report errors on the exec,
# only on the dialog itself
catch {exec /etc/rc.d/init.d/httpd restart >&/dev/null}
sleep 5
# redo test, fail if get an error again
spawn telnet localhost 80
expect {
"Connected to" {}
default {
flush stdout;
exit 1;
}
}
}
}

# GET HTTP HEADER
send "HEAD / HTTP/1.0\r"
send "\r"
expect {
"HTTP/1.1 200 OK" {}
default { # fail if we don't get an OK
flush stdout;
exit 2;
}
}

exit 0;
------------------------------------------