--[[ ●show コマンド実行スクリプト  ・show のコマンドを一定の間隔で実行し、その結果をメールで送信するスクリプトで   す。show のコマンドは、複数指定することができます。 <説明> ・このファイルを RTFS か外部メモリに保存してください。 ・本項目の config の設定では schedule at コマンドでルーター起動時に Lua スク リプトが実行されるように設定しています。 ・スクリプトを停止するときは terminate lua コマンドを実行してください。 ・再度、Lua スクリプトを実行する場合は lua コマンドで実行してください。 ・★マークの付いた設定値は変更が可能です。 <ノート>  ・メールの送信失敗時に出力する SYSLOG レベルを指定可能です。   SYSLOG のレベルを指定するには、log_level を設定してください。   debug レベル、notice レベルの SYSLOG を出力するためには、それぞれ以下の設定   が必要です。    debug レベル ・・・ syslog debug on    notice レベル・・・ syslog notice on  ・本スクリプトファイルを編集する場合、文字コードは必ず Shift-JIS を使用してく   ださい。 ]] --------------------------## 設定値 ##-------------------------------- -- 監視間隔(1 - 864000 秒) idle_time = (監視間隔) -- ★ -- 監視間隔ごとに結果を通知する show コマンドをカンマで区切って列挙する cmd_tbl = { -- ★ "(show コマンド1)", "(show コマンド2)" } -- メールの設定 mail_tbl = { -- ★ smtp_address = "(SMTP サーバのアドレス)", from = "(送信元メールアドレス)", to = "(宛先メールアドレス)" } -- メールの送信に失敗したときに出力する SYSLOG のレベル (info, debug, notice) log_level = "(SYSLOG レベル)" -- ★ ----------------------## 設定値ここまで ##---------------------------- ------------------------------------------------------------ -- コマンドの実行結果を出力する関数 -- ------------------------------------------------------------ function exec_command(cmd) local rtn, str rtn, str = rt.command(cmd) if (not rtn) or (not str) then str = "実行失敗\r\n" end return rtn, string.format("# %s\r\n%s\r\n", cmd, str) end ------------------------------------------------------------ -- 現在の日時を取得する関数 -- ------------------------------------------------------------ function time_stamp() local t t = os.date("*t") return string.format("%d/%02d/%02d %02d:%02d:%02d", t.year, t.month, t.day, t.hour, t.min, t.sec) end ------------------------------------------------------------ -- メインルーチン -- ------------------------------------------------------------ local rtn, str while (true) do mail_tbl.text = "" for i, cmd in ipairs(cmd_tbl) do rtn, str = exec_command(cmd) mail_tbl.text = mail_tbl.text .. str end mail_tbl.subject = string.format("summary of show commands (%s)", time_stamp()) rtn = rt.mail(mail_tbl) if (not rtn) then rt.syslog(log_level, "failed to send mail. (Lua スクリプトファイル名)") end rt.sleep(idle_time) end