加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – 如何创建一个脚本来顺序执行多个“exec”命令?

发布时间:2020-12-16 01:52:20 所属栏目:安全 来源:网络整理
导读:我是 Linux Shell Scripting的新手,想知道是否有人可以帮我解决以下问题. 我创建了一个脚本来与我的linux机器同步时间,但只有一个exec命令似乎完成 #!/bin/bash#Director SMS Synch Time Scriptecho The current date and time is:dateechoecho Synching GTS
我是 Linux Shell Scripting的新手,想知道是否有人可以帮我解决以下问题.

我创建了一个脚本来与我的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 root@128.221.252.35 "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 root@128.221.252.36 "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 root@128.221.252.67 "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 root@128.221.252.68 "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 root@128.221.252.69 "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 root@128.221.252.70 "ntpd -q -g"
echo Finished synching director-2-2-B

sleep 2

echo

echo
echo Finished Synching SVT Cluster 2 directors with SMS.

该脚本似乎只在第一个exec命令后完成.

2011年8月25日星期四12:40:44

将GTS Cluster 1控制器与SMS同步.

更改导演1-1-A的日期和时间

任何帮助将不胜感激=)

解决方法

exec的全部意义在于取代当前的流程.在shell脚本中,这意味着shell被替换,并且在执行exec之后不再执行任何操作.我疯狂的猜测是:也许你想用&相反(ssh …&)?

但是,如果您只是想按顺序运行ssh,每次等到它完成后,只需删除’exec’字样即可.没有必要用exec表达“我想运行this_command”.只需this_command即可.

哦,把它变成#!/ bin / sh脚本;你的脚本中没有bashism或linuxism.如果可以的话,最好避免使用bashisms.这样,如果您的老板决定切换到FreeBSD,您的脚本可以不加修改地运行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读