IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

分類:

如何建立對某一個網站‧定時PING的記錄

01. 今天高層(這裡好像每人也是高層)要求在某段日子期間,每小時測試對某一個網站的PING數據。天知那人會每天都座在電腦面前,就是為了一小時的按下那幾個鍵盤的鍵。

02. 要求很簡單,就是PING一個網站,再把數據存入檔案儲存。

ping www.yahoo.com > c:\\yahoo\\ping_1.txt

03. 想也不想,這些根本就是應該電腦做的事,死也不會用人手去做。結果變成如下的Batch script。

@echo off
set d=%date:/=-% ::get date from the system and then change character / to character -
set d1=%d:~0,10% ::get the first 10 characters
set t=%time: =0% ::get time from the system and then add zero in the prefix for AM time
set t1=%t::=-% ::replace character : in time to character -
set t2=%t1:~0,5% ::get the first 5 characters from time

rem date /T >> c:\\sap\\pingBHG_%d1%-%t2%.txt ::if you want to save date to file
rem time /T >> c:\\sap\\pingBHG_%d1%%-t2%.txt ::if you want to save date to file
ping sapI23ms.sapms.fresenius.de >> c:\\sap\\pingBHG_%d1%-%t2%.txt ::ping the result into file
rem echo. >> c:\\sap\\pingBHG_%d1%-%t2%.txt ::if you want to save one blank line to file

04. 最後,當然是用Windows工作排程器(Windows Task Scheduler)去建立每小時執行以上script。打開Windows工作排程器。

05. 建立工作(Create Task)。

06. 在『一般』(General)中,輸入名稱(Name)、選擇當執行工作時的使用者帳戶(When running the task, use the following user account)、選擇不論使用者登入與否均執行(Run whether user is logged on or not)。

07. 在『觸發程序』(Triggers)中,新增觸發條件。

08. 在『動作』(Actions)中,新增要執行檔案。

09. 因為是手提電腦關係,在『條件』(Conditions)中,選擇不論使用外置電源及電池皆執行程式。

10. 完成後按『確定』。

11. 完成後,選擇在工作排程器程式庫(Task Scheduler Library),便可以在中間位置看到剛才設定的排程項目。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *