VirtualBox start with script / Run script on host when guest starts?

Discussions related to using VirtualBox on Linux hosts.
Post Reply
markd89
Posts: 34
Joined: 4. Sep 2016, 22:54

VirtualBox start with script / Run script on host when guest starts?

Post by markd89 »

Hi,

I am running Virtualbox host on Debian 9 with a Windows guest/

Two questions:

1. When my Windows guest is running, ifconfig shows the vboxnet1 is up.

Is there a way to script starting this network so that it is up without me starting VirtualBox? I know it isn't going to "do" anything without Virtualbox running, but if I could have the network name up and the IP allocated that would be enough.

2. Is there a way to run a script on the HOST when the Guest is started. i.e. My Windows guest is started, then something.sh is executed on the Linux host side?

Thanks much!

Mark
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: VirtualBox start with script / Run script on host when guest starts?

Post by socratis »

  1. No, it doesn't make sense if there is no VM that requires that network. In my tests (OSX host), once a VM that requires the HostOnly network has run, the IP will be allocated, even if all VirtualBox processes have exited.
  2. How about starting the guest from the script and then execute whatever you want from the script?
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
markd89
Posts: 34
Joined: 4. Sep 2016, 22:54

Re: VirtualBox start with script / Run script on host when guest starts?

Post by markd89 »

socratis wrote:
  1. No, it doesn't make sense if there is no VM that requires that network. In my tests (OSX host), once a VM that requires the HostOnly network has run, the IP will be allocated, even if all VirtualBox processes have exited.
  2. How about starting the guest from the script and then execute whatever you want from the script?
Thanks, Socratis, I appreciate the ideas.

A little more background: I have a script that needs the vboxnet1 network to be up before it can properly start. I could run it from cron every few minutes and and check if vboxnet1 is up, but I was looking for a cleaner solution that doesn't involve running the script over and over. Worst case is I will just do that.

I did more digging and thought I had found the answer by putting a script in /etc/NetworkManager/dispatcher.d

Code: Select all

#!/bin/sh -e
echo 1="$1" 2="$2" > /home/mark/nw.txt
exit 0
When I cat nw.txt I see the most recent network that came up, i.e. wlan0, vpn, etc. However when vboxnet1 comes up, it does not seem to get caught and the text file contains the status of the previous device. Is there another way to run a script when vboxnet1 comes up?

Thanks again,
Mark
Post Reply