我已经完成了作业,但我想我可能会在这里混合苹果和橙子。我的脚本旨在运行一系列远程内联命令,退出,然后运行一些额外的 LOCAL 命令。它必须首先远程完成,因为这些服务用于故障转移代理。问题是远程 ssh 线路断开后,整个脚本就停止了。我不确定为什么断开连接会停止整个脚本。也许出口线是罪魁祸首?
#!/bin/bash
#
### Run remote svc restarts and then Local restarts
#
exec ssh -t REMOTEHOST 'stop svc1; restart svc2; start svc3; exit'
(SCRIPT FAILS HERE)
## Run local shell (This works independently, but not in the entire script)
rst=`pgrep -n failoversvc`
echo "Stopping 1st service at `date | awk '{print $2,$3,$4}'`" && service 1 stop >> SYNCLOG.txt
sleep 2
echo "Restarting 2nd service at `date | awk '{print $2,$3,$4}'`" && service 2 restart >> SYNCLOG.txt
if rst="";then
echo "Starting 3rd service at `date | awk '{print $2,$3,$4}'`" && service 3 start >> SYNCLOG.txt
else
echo "3rd Service PID not found! Check for functionality"
fi
我看了看,但这我无法得到我正在寻找的结果。