I tried using VBoxManage guestproperty wait <vmname> ... but what looked like obvious patterns didn't work. I'm writing a script which imports a new VM, configures it, launches it, takes a snapshot, and then closes it, and obviously I need to know when the VM is running before taking the final two steps.
Thanks.
You can use showvminfo output:
for Linux:
VBoxManage showvminfo "vm_name" | grep State
for Windows:
VBoxManage showvminfo "vm_name" | findstr State
See the thread below:
https://unix.stackexchange.com/questions/28611/how-to-automatically-start-and-shut-down-virtualbox-machines
Related
So, I'm using Google Cloud Platform and set below startup script
#! /bin/bash
cd /home/user
sudo ./process1
sudo ./process2
I worried about this script because process1 blocks shell and prevent to run sudo ./process2. And it really was. process1 was started successfully but process2 was not started.
I checked that script has no problem with starting process1 and process2. Execute ./process2 via SSH worked but after I close the SSH shell and process2 was stopped too.
How can I start both process in booting time(or even after)?
I tried testing your startup script in my environment,it seems the script works well.
1.You can please try checking process1 and process2 scripts.
2.If you want your process to run in the background even after the SSH session is closed, you can use “&” { your_command & }at the end of your command.
To run a command in the background, add the ampersand symbol (&) at the end of the command:
your_command &
then the script execution continues and isn't blocked. Or use linux internal means to auto run processes on boot.
I have a bash script which will take 5-6 hrs to complete and yesterday i accessed aws 12 month free tire and running ec2 (ubuntu) on it ,i want to run that bash script even after i close my main machine ...how can i do this ?
Assuming this is on linux system, you can run your script in the background using & optons. Something like this
yourBashScript.sh &
Where & tells the shell to run it in the background. So even if you close the shell or end your ssh session, it will keep running in the background till it finishes the job or crashes due to any error.
You can always check whether your script is running or not using ps command. Something like this
ps -eaf | grep yourBashScript
this may return the process information for your script, if it is in running state.
I'd like to disable time synchronization from the VM in virtual box. I've found that the next commands have to be sent before launch the vm:
VBoxManage setextradata <YOUR_VM_NAME> "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
VBoxManage setextradata <YOUR_VM_NAME> "VBoxInternal/TM/TSCTiedToExecution" 1
So, my question is: Do I have to launch these commands every time that I start the vm or only once?
I've found the way to read the options with parameter "getextradata". So, the answer is that the options are stored after a reboot. So it is necessary to do it once.
VBoxManage getextradata "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled"
VBoxManage getextradata "VBoxInternal/TM/TSCTiedToExecution"
I have a bash script. I would like to run it continuously on google cloud server. I connected to my VM via SSH in browser but after I've closed my browser, script was stopped.
I tried to use Cloud Shell but if I restart my laptop, script launches from start. It doesn't work continuously!
Is it possible to launch my script in google cloud, shut down laptop and be sure what my script works?
The solution: GNU screen. This awesome little tool let's you run a process after you've ssh'ed into your remote server, and then detach from it - leaving it running like it would run in the foreground (not stopped in the background).
So after we've ssh'ed into our GCE VM, we will need to:
1. install GNU screen:
apt-get update
apt-get upgrade
apt-get install screen
type "screen". this will open up a new screen - kind of similar in look & feel to what "clear" would result in.
run the process (e.g.: ./init-dev.sh to fire up a ChicagoBoss erlang server)
type: Ctrl + A, and then Ctrl + D. This will detach your screen session but leave your processes running!
feel free to close the SSH terminal. whenever you feel like it, ssh back into your GCE VM, and type screen -r to resume your previously detached session.
to kill all detached screens, run:
screen -ls | grep pts | cut -d. -f1 | awk '{print $1}' | xargs kill
You have the following options:
1. Task schedules - which involves cron jobs. Check this sample. Via this answer;
2. Using startup scripts.
I performed the following test and it worked for me:
I created an instance in GCE, SSH-d into it and created the following script, myscript.bash:
#!/bin/bash
sleep 15s
echo Hello World > result.txt
and then, ran
$ bash myscript.bash
and immediately closed the browser window holding the SSH session.
I then waited for at least 15 seconds, re-engaged in an SSH connection with the VM in question and ran $ ls and voila:
myscript.bash result.txt
So the script ran even after closing the browser holding the SSH session.
Still, technically, I believe your solution lies with 1. or 2.
You can use
nohup yourscript.sh > output_log_file.log
I faced similar issue. I logged into Virtual Machine through google cloud command on my local machine, tried to exit by closing the terminal, It halted the script running in the instance.
Use command exit to log out of cloud consoles in local machine putty console (twice).
Make sure you have not enabled "PREEMPT INSTANCE" while creating a VM instance.
It will force to close the instance within 24 hours to reduce the costing by a huge difference.
I have a NodeJS project and I solved with pm2
I want to copy a file to a vm using guestcontrol copyto. I have had a lot of trouble with the documentation which has not been fully updated with the changes in VirtualBox 5 and have also found that the copy commands broke in VirtualBox 5.
It seems that there will be a fix in the next version, but is there a workaround to use until that time?
I can read a file to stdout using run + cat:
VBoxManage guestcontrol 1-echo --username root --password root run /bin/cat /etc/network/interfaces
but I can't use stdin to write a file as it looks like the signal to close the stdin isn't forwarded to the guest (this creates the file and hangs without writing anything):
echo "Hello" | VBoxManage guestcontrol 1-echo --username root --password root run --no-wait-stdout /usr/bin/tee /test