How do I know when a virtual virtual machine is ready to accept SSH connections?

I am writing a simple script that creates a new VirtualBox virtual machine, deploys it, and then connects to it via SSH to execute some commands. The problem is that I have to wait a certain time to load the virtual machine. I am currently just doing sleep 120 in my script to sleep for 2 minutes. However, instead of waiting 2 minutes, I would like to receive some kind of notification when the VM boots up and is ready to accept SSH connections. Is it possible?

PS: Solutions involving guest add-ons will not work - OS on the guest side is vanilla CentOS 5.7, guest add-ons are not installed.

+4
source share
2 answers

You can replace sleep 120 with something like

 while :; do ssh guest && break sleep 10 done 

just keep trying until you get through.

+2
source

I do this with my notification-when-up2 script: http://stromberg.dnsalias.org/~strombrg/notify-when-up2.html

It will give you an email and a popup when the port starts accepting connections, by the way.

EG: notify-when-up2 -n remote.host.com 22

0
source

Source: https://habr.com/ru/post/1386207/


All Articles