我对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