2014-10-22 53 views
0
#!/bin/bash 
while : 
do 
    echo twerkin 
    exec free -h > /ver/www/raspberry/load.txt 
    exec /opt/vc/bin/vcgencmd measure_temp > /var/www/raspberry/heat.txt 
done 

這就是我所做的,我將在我的網站上閱讀它,但那不是問題。問題是,它給了我這個錯誤:Bash exec無限while循環不起作用

[email protected] ~ $ sh showinfo.sh 
showinfo.sh: 7: showinfo.sh: Syntax error: "done" unexpected (expecting "do") 

我在我的Raspbian(Debian的喘息)樹莓派

+1

請將錯誤添加到問題 – arco444 2014-10-22 10:26:24

+0

添加錯誤,(以前在圖像中) – 2014-10-22 10:31:24

+1

使用'sh'運行Bash腳本始終是錯誤。但是你的腳本在這裏工作得很好(除了明顯誤解'exec'的作用)沒有錯誤。 – tripleee 2014-10-22 10:32:39

回答

2

你似乎並不理解exec關鍵字做什麼運行此。它用您的當前腳本(基本上,while循環)用free命令替換

要運行一個命令,只需指定它。

#!/bin/bash 

while : ; do 
    free -h 
    /opt/vc/bin/vcgencmd measure_temp 
done 

(我省略了重定向,因爲你是覆蓋在每次迭代舊的結果。那你真的想要?)

+0

如何讓bash運行另一個程序? – 2014-10-22 10:32:21

+0

已更新的回答。 – tripleee 2014-10-22 10:34:31

+0

我想從每個我在2個獨立文件中運行的東西輸出,所以free/h在/var/www/raspberry/load.txt中,以及從/ opt/vc/bin/vcgencmd中的輸出measure_temp在/ var/www/raspberry/heat.txt,以便我可以用HTML讀取它們。 – 2014-10-22 10:51:42

0

嘗試改變你的腳本幾件事情

#!/bin/bash 

while : ; 
do 
    echo twerkin 

    #### commands to execute are not need to be prefixed with exec 
    #### + concatenate output with >> 
    free -h >> /ver/www/raspberry/load.txt 

    #### same here 
    /opt/vc/bin/vcgencmd measure_temp >> /var/www/raspberry/heat.txt 

    #### you probably would want to add a delay here, because in other way 
    #### the script will be executed probably way too fast 
    # sleep 0.01 

done 
+0

感謝您的輸入!但它給這個錯誤: PI @覆盆子〜$ ./showinfo.sh :沒有這樣的文件或目錄 – 2014-10-22 14:52:33

+0

我找到了另一種方式來做到這一點不循環,我不知道爲什麼它不工作。它與SSH有什麼關係? – 2014-10-22 14:59:43