2017-05-29 149 views
0

當我執行命令bash腳本輸出

top -c -b -n | grep XXX > TEST 

在Red Hat Linux命令行,所有的路徑和的東西從top命令其餘的出口到TEST文件(在一個例如,它寫了超過100列/字符)。

然而,當我在腳本中添加相同的命令,並且經由crontab運行它,輸出僅是直到81列/字符的每一次。

我怎樣才能獲得在cron腳本的全寬度的信息?

回答

0

你可以嘗試以下方法:

COLUMNS=1000 top -c -b -n 1 | grep XXX > TEST 

這將確保柱環境變量的值設置爲一個較大的值。

致謝:ServerFault

+1

非常感謝您的回答是真的很有幫助。 伊戈爾Kuzmitshov它一直像一個魅力。 – pet238

1

的解釋是在man top第1節:

-w :Output-width-override as: -w [ number ] 
     In Batch mode, when used without an argument top will 
     format output using the COLUMNS= and LINES= environment 
     variables, if set. Otherwise, width will be fixed at 
     the maximum 512 columns. With an argument, output 
     width can be decreased or increased (up to 512) but the 
     number of rows is considered unlimited. 

     In normal display mode, when used without an argument 
     top will attempt to format output using the COLUMNS= 
     and LINES= environment variables, if set. With an 
     argument, output width can only be decreased, not 
     increased. Whether using environment variables or an 
     argument with -w, when not in Batch mode actual termi‐ 
     nal dimensions can never be exceeded. 

     Note: Without the use of this command-line option, out‐ 
     put width is always based on the terminal at which top 
     was invoked whether or not in Batch mode. 

COLUMNSLINES由終端在啓動時,當你調整它的窗口中設置。

+0

感謝您的幫助....我從來沒有注意到它。 :( – pet238