当 apt-get 完成时,通过 ssh 运行的非交互式脚本被中断

当 apt-get 完成时,通过 ssh 运行的非交互式脚本被中断

当我在 Ubuntu Server 13.04 上运行以下非交互式脚本时,它会被中断:lxc-docker包完成安装。

脚本 :

ssh -o StrictHostKeychecking=no -t -t -i $CERT $USER@$SERVER <<'ENDSSH'

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common
sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:dotcloud/lxc-docker
sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install lxc-docker

echo "some other actions here..."

exit #SSH session

ENDSSH
exit

一切似乎都很好,但脚本在输出中的这一行之后被中断:

Processing triggers for ureadahead ...

1)为什么会发生这种情况?我怎样才能防止这种情况发生?

2) 如果没有,我如何检测 ssh 会话是否已成功完成?

安装的最后几行(缩短):

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  bridge-utils bsdtar cgroup-lite debootstrap dnsmasq-base libapparmor1
  libarchive13 libcap2-bin liblxc0 liblzo2-2 libnetfilter-conntrack3
  libnettle4 libpam-cap libseccomp1 lxc lxc-templates python3-lxc
Suggested packages:
  bsdcpio lrzip libcap-dev btrfs-tools lvm2 lxctl qemu-user-static
The following NEW packages will be installed:
  bridge-utils bsdtar cgroup-lite debootstrap dnsmasq-base libapparmor1
  libarchive13 libcap2-bin liblxc0 liblzo2-2 libnetfilter-conntrack3
  libnettle4 libpam-cap libseccomp1 lxc lxc-docker lxc-templates python3-lxc
0 upgraded, 18 newly installed, 0 to remove and 29 not upgraded.
Need to get 2,495 kB of archives.
After this operation, 8,742 kB of additional disk space will be used.
Get:1 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ raring/main liblzo2-2 amd64 2.06-1build1 [53.2 kB]
Get:2 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ raring/main libnettle4 amd64 2.4-3 [94.7 kB]
.
.
.
.
.
.
Setting up libnetfilter-conntrack3:amd64 (1.0.1-1) ...
Setting up dnsmasq-base (2.65-1ubuntu1) ...
Setting up python3-lxc (0.9.0-0ubuntu3.2) ...
Setting up lxc (0.9.0-0ubuntu3.2) ...
lxc start/running
Setting up lxc dnsmasq configuration.
Setting up bsdtar (3.1.2-5ubuntu1) ...
Setting up libcap2-bin (1:2.22-1.2ubuntu2) ...
Setting up libpam-cap:amd64 (1:2.22-1.2ubuntu2) ...
Setting up cgroup-lite (1.8) ...
cgroup-lite start/running
Setting up debootstrap (1.0.46ubuntu1) ...
Processing triggers for ureadahead ...
Setting up lxc-docker (0.4.0-1) ...
docker start/running, process 2444
Setting up lxc-templates (0.9.0-0ubuntu3.2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for ureadahead ...

答案1

只是为了说明明显的情况(作为解决方法,而不是正确的解决方案),也许尝试将脚本发送到服务器,然后执行脚本...?

$ cat<<ENDSSH > /tmp/tmp.sh
sudo DEBIAN_FRONTEND=noninteractive apt-get ...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install lxc-docker
echo "some other actions here..."
exit
ENDSSH

进而,

$ scp  /tmp/tmp.sh ${USER}@${SERVER}:/tmp/tmp.sh \
  && ssh $USER@$SERVER 'chmod u+x /tmp/tmp.sh && /tmp/tmp.sh; rm /tmp/tmp.sh'

如果这也终止,则远程命令可能必须在后台运行,断开连接,然后使用另一个 ssh 命令来检查执行脚本的结果。

相关内容