我試圖組成一個命令,將被彎曲,使其每隔幾分鐘的監控服務器腳本的穩定性(腳本實際路徑替換):egrep的輸出不轉發所有的行到文件
while :; do date +"%T" >> monitor.txt; time curl -Is http://googel.com | egrep "HTTP|m.\." >> monitor.txt; echo ================ >> monitor.txt; sleep 30; done
問題是,出於某種原因,部分輸出不會被轉發到文件monitor.txt。因此,文件中包含以下行:
$ cat monitor.txt
19:39:10
HTTP/1.1 301 Moved Permanently
================
19:39:40
HTTP/1.1 301 Moved Permanently
================
..while時間的細節去默認輸出:
$ while :; do date +"%T" >> monitor.txt; time curl -Is http://googel.com | egrep "HTTP|m.\." >> monitor.txt; echo ================ >> monitor.txt; sleep 30; done
real 0m0.075s
user 0m0.005s
sys 0m0.003s
real 0m0.106s
user 0m0.004s
sys 0m0.005s
可否請你指出,我缺少什麼嗎?基本上我會在後臺運行這個命令,並檢查monitor.txt的結果。
預先感謝您!
'時間'[適用於整個管道](https://www.gnu.org/software/bash/manual/bashref.html#Pipelines),而不僅僅是第一條命令。 – melpomene