該怎麼設計讓shell script能寫入時間? - Linux

Jessica avatar
By Jessica
at 2010-01-31T12:19

Table of Contents

time 是個 bash build in function. 所以你用正常的 command 導向
(redirections) 是取不到你要的資料的。

測試如下.
lloyd@baby's bottle:$ time ls 1> /dev/null 2> /tmp/log

real 0m0.002s
user 0m0.000s
sys 0m0.000s

lloyd@baby's bottle:$ { time ls 1> /dev/null 2> /tmp/elog ; } > /tmp/log

real 0m0.004s
user 0m0.004s
sys 0m0.000s

lloyd@baby's bottle:$ { time ls 1> /dev/null 2> /tmp/elog ; } 2> /tmp/log
lloyd@baby's bottle:$ cat /tmp/log

real 0m0.002s
user 0m0.004s
sys 0m0.000s

不過你的問題實事上也沒那樣複雜,作法如下
lloyd@baby's bottle:$ cat run.sh
#!/bin/bash
time ls > /dev/null

#> ./run.sh 2> /tmp/log

※ 引述《CrazyRat (瘋老鼠)》之銘言:
: 我寫了一個shell script
: 大致如下
: #!/bin/sh
: time ./test xxxxx > /dev/null
: time ./test2 xxxxx > /dev/null
: 然後把他存成一個run.sh
: 接著執行run.sh
: 我希望的結果是
: 把time測出來的時間寫到一個檔案
: 但是似乎失敗了
: run.sh > result(result不會紀錄到任何時間的資料)
: 該怎麼寫才正確呢?
: 感謝m(_ _)m

--
Tags: Linux

All Comments

ubuntu ssh的問題

Brianna avatar
By Brianna
at 2010-01-31T02:53
※ 引述《knight30115 (無敵人)》之銘言: : 大家好, : 這是小弟第一次使用ubuntu : 昨天因為功課需要,要把兩台電腦用openssh連接起連來 : 所以我先照這個blog的步驟跑了一次 : http://blog.udn.com/nigerchen/2262865 : port我也改成 ...

debian不吃deb包

Catherine avatar
By Catherine
at 2010-01-31T01:23
剛剛用vbox裝debian試用 卻發生這種事 http://i.imgur.com/I4s2Q.png http://i.imgur.com/KWx1i.png ...不吃deb是要吃什麼 囧a -- 應該不會是vbox的關係吧orz -- 男公關部 vs KERORO小隊 相 ...

Ubuntu 中文字的問題

Victoria avatar
By Victoria
at 2010-01-30T23:38
我用的是 Ubuntu linux, 我發現有個中文字顯示的問題.... 有切換過 scim 和 gcin來試, 發覺都有一樣的問題,不確定是什麼樣的bug.... 是這樣的, 比方說, 我現在用gcin詞音輸入and#34;閃and#34;(ㄕㄢˇ)這個字, 可是我現在看到的卻是and#34;門and# ...

檢查DNS的設定是否正確?

Linda avatar
By Linda
at 2010-01-30T15:15
請問一下 我用 bind 架了 dns 要如何知道是不是正常運作?? 是不是有一些可以查詢的網站? 正查?反查? 謝謝~ -- 無名暗黑連結,鄉民低調服用。 _________________________________________________ - ...

ubuntu ssh的問題

Kama avatar
By Kama
at 2010-01-30T13:33
大家好, 這是小弟第一次使用ubuntu 昨天因為功課需要,要把兩台電腦用openssh連接起連來 所以我先照這個blog的步驟跑了一次 http://blog.udn.com/nigerchen/2262865 port我也改成91 不過因為第一次弄,我想先試試看 就沒有設定allow和deny ...