指定コマンドを毎分実行し続けるマクロ
システムに手を入れた翌営業日とか、設定変更した後とか、手動監視で毎分ステータスを確認したりしなきゃいけない時がある。そんな時に。(毎日やるなら、ちゃんとperlとかで書いた方が良いですが)
ちなみにTeraTermは"UTF-8 TeraTerm Pro with TTSSH2"のVer4.51で動作確認してますが、当然使用は自己責任で。:-)
;================================================ ; AutoExecPerMinute v1.0 ; # 毎分コマンドを実行し続ける。 ; # 指定時になったら終了。 ;================================================ ;; [終了時間の指定] intEndTime = 9 ;; [ ログファイルの指定 ] ;; LOGDIR\PREFIX-YYYYMMDD-HHMMSS.EXTENTION ;; [環境変数"TEMP"にログを保管] getenv 'TEMP' LOGDIR strconcat LOGDIR '\' PREFIX = 'teraterm' EXTENTION = '.log' call MyLogging call MyGetTime logwrite strTimebuf ;; [コマンド実行ループ] ;; ※変数iを使えば回数制限可能。 ;; "i = i - 1"がコメントアウトしてあると無限ループ。 i = 10 while i>0 if intHourbuf=intEndTime then logwrite 'Loop END because a finish time. '#13#10 ;; [終了処理] call MyEnding end endif call MyGetTime logwrite #13#10 logwrite strTimebuf logwrite #13#10 call MyCMD1 intSetMin=intMinbuf while intMinbuf=intSetMin call MyGetTime pause 1 endwhile ;i = i - 1 endwhile end ;;--------------------------------------------- ;; [実行コマンド] :MyCMD1 sendln 'date' sendln 'ls' return ;;--------------------------------------------- ;; [システム時刻の取得] :MyGetTime gettime strTimebuf strcopy strTimebuf 1 2 strHourbuf strcopy strTimebuf 5 1 strMinbuf str2int intHourbuf strHourbuf str2int intMinbuf strMinbuf return ;;-------------------------------------------- ;; [終了処理] :MyEnding sendln 'exit' return ;;--------------------------------------------- ;; [システム日付の取得] :MyLogging getdate strDate strcopy strDate 1 4 strYear strcopy strDate 6 2 strMonth strcopy strDate 9 2 strDay ;; [システム時刻の取得] gettime strTime strcopy strTime 1 2 strHour strcopy strTime 4 2 strMinute ;strcopy strTime 7 2 strSecond ;; [ログファイル名を組み立てる] ;; (ログファイルの命名規則に合わせて変更してください) LOGFILE = LOGDIR strconcat LOGFILE PREFIX strconcat LOGFILE '-' strconcat LOGFILE strYear strconcat LOGFILE strMonth strconcat LOGFILE strDay strconcat LOGFILE '-' strconcat LOGFILE strHour strconcat LOGFILE strMinute ;strconcat LOGFILE strSecond strconcat LOGFILE EXTENTION logopen LOGFILE 0 0 return
ちなみに環境変数"TEMP"のディレクトリが解らない、階層が深くてログファイルを見つけるのが面倒という方は、ファイル名を指定して実行で%temp%と入力するか、エクスプローラのアドレスバーで同様に%temp%とか入力すると、一発でTEMPに行けるので安心。