Sometimes remote (via ssh) Linux shell script won't exit

820 Views Asked by At

I have some basic Linux shell scripts for deploying new Ubuntu VMs in Azure.

The deploy.sh script is run locally and it uses Azure CLI to create a VM. Next, it makes an ssh connection to the newly created VM and sends a script called cloud-init.sh which installs some packages. This script always runs fine with no issues.

However, when the cloud-init.sh script ends, it sometimes won't return control to the deploy.sh script. It may return immediately, in 10 minutes or never...

I've tried various methods of indicating that the script is done (you'll see them below) but none of them do the trick. Any ideas?

Here's the ssh command from the deploy.sh script:

ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -T -i $SSHPEM $SSHUSERNAME 'bash -s' < cloud-init.sh

Here's the tail of the cloud-init.sh script:

echo "--------------------------------------------"
echo "cloud-init script ended at" $(date +"%T")
echo "--------------------------------------------"
exit 0
&
^D

Thanks in advance.

0

There are 0 best solutions below