我對Linux Shell腳本非常新穎,並想知道是否有人可以幫我解決以下問題。如何創建一個腳本來順序執行多個「exec」命令?
我創建了一個腳本我的Linux機器,以同步的時間,但只有一個exec命令似乎完成
#!/bin/bash
#Director SMS Synch Time Script
echo The current date and time is:
date
echo
echo Synching GTS Cluster 1 directors with SMS.
echo
echo Changing date and time for director-1-1-A
exec ssh [email protected] "ntpd -q -g"
echo Finished synching director-1-1-A
echo
sleep 2
echo Changing date and time for director-1-1-B
exec ssh [email protected] "ntp -q -g"
echo Finished synching director-1-1-B
echo
sleep 2
echo Finished Synching GTS Cluster 1 directors with SMS.
sleep 2
echo
echo Synching SVT Cluster 2 directors with SMS.
echo
echo Changing date and time for director-2-1-A
exec ssh [email protected] "ntpd -q -g"
echo Finished synching director-2-1-A
echo
sleep 2
echo Changing date and time for director-2-1-B
exec ssh [email protected] "ntpd -q -g"
echo Finished synching director-2-1-B
echo
sleep 2
echo Changing date and time for director-2-2-A
exec ssh [email protected] "ntpd -q -g"
echo Finished synching director-2-2-A
echo
sleep 2
echo Changing date and time for director-2-2-B
exec ssh [email protected] "ntpd -q -g"
echo Finished synching director-2-2-B
sleep 2
echo
echo
echo Finished Synching SVT Cluster 2 directors with SMS.
腳本似乎只有第一exec命令後完成。
週四8月25日12時40分44秒EDT 2011
Synching GTS集羣1名董事短信。
改變的日期和時間爲導演-1-1-A
任何幫助,將不勝感激=)
man exec將解釋爲什麼發生這種情況。擺脫高管,你應該是金。 OTOH這看起來像是一些嚴重的ntpd濫用! – fvu
你必須告訴我們爲什麼你需要執行每個ssh。 ':g/exec/s/exec //'(刪除所有可執行文件,它應該可以工作)。祝你好運。 – shellter
@fvu:'man sh'可能是一個更好的方法來找出'exec'內置的功能。 – Jens