[SOLVED] VBoxManage script runs manually but not from cron

Questions about virtualization software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
FuLl

[SOLVED] VBoxManage script runs manually but not from cron

Post by FuLl »

I originally asked this question on the VirtualBox forums [0], & was told to ask here since the VirtualBox version in the Linux Mint repos is forked & is not official. So here I am. Thanks in advance.

I'm on Linux Mint 18.3 with VirtualBox version 5.1.38_Ubuntu r122592.

I have the following in my user's crontab:

Code: Select all

0 12 * * 1 sh /home/user/Scripts/Show_Headless_VMName_UI_Now.sh
And this is the script it calls:

Code: Select all

#!/bin/bash
VBoxManage startvm /home/user/VM/VMName/ VMName --type=separate 
VBoxManage controlvm VMName setvideomodehint 1440 900 32
I'm able to run that script successfully from a KDE menu launcher, & manually in a console, each with this command:

Code: Select all

sh /home/user/Scripts/Show_Headless_VMName_UI_Now.sh
But from cron it fails somehow. Could use a hand.

[0]
https://forums.virtualbox.org/viewtopic.php?f=7&t=90748
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: VBoxManage script runs manually but not from cron

Post by rene »

Your startvm line seems odd. I with VirtualBox 5.2.22 r126460 on Mint 19 need either

Code: Select all

VBoxManage startvm VMName --type=separate
or

Code: Select all

VBoxManage startvm ~/VirtualBox\ VMs/VMName/VMName.vbox --type=separate
When I from the command line or user crontab use your syntax,

Code: Select all

VBoxManage startvm /home/rene/VirtualBox\ VMs/VMName/ VMName --type=separate 
then VM "VMName" starts successfully but only as a result of the second, lone "VMName"; the first path parameter is also intepreted as a VM and gives the error message,

Code: Select all

VBoxManage: error: Could not find a registered machine named '/home/rene/VirtualBox VMs/VMName'
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(pszVM).raw(), machine.asOutParam())" at line 595 of file VBoxManageMisc.cpp
It's sort of expected that you would've noticed if also for you so perhaps I'm looking at a version difference here, and the VM does as said start both from command line and cron, but what happens for you if you use just "VMName" or "/home/user/VM/VMName/VMName.vbox"? Generally speaking, I could imagine an environment difference leading to inability to locate ~/.config/VirtualBox and although that's apparently not in fact the case for me, maybe it still is for you on 18.3.

[EDIT] Oh, by the way, let me also immediately ask: your "VBoxManage" is in /usr/bin, right? If it's somewhere more original specify the complete path due to cron jobs having a minimal PATH; a minimal environment.
FuLl

Re: VBoxManage script runs manually but not from cron

Post by FuLl »

rene wrote: Thu Dec 13, 2018 12:55 am let me also immediately ask: your "VBoxManage" is in /usr/bin, right? If it's somewhere more original specify the complete path due to cron jobs having a minimal PATH; a minimal environment.
Yes, it's at that path.
rene wrote: Thu Dec 13, 2018 12:55 am Your startvm line seems odd.
Thanks, this is what led me to a solution.

I first looked at 'startvm' in the official docs [0], & didn't see a reason why I had my syntax that way. Clearing that path information allowed it to work both from CLI & cron. This is my script now:

Code: Select all

#!/bin/bash
VBoxManage startvm VMName --type=separate
sleep 15
VBoxManage controlvm VMName setvideomodehint 1440 900 32
Note that I added the sleep in between there. This is because while that video mode would successfully apply itself when using that command to 'Show' a running headless VM, it would run too soon in cases where that command was starting a detachable VM. Thus 15 seconds added & now that part works.

Marking solved, thanks again rene!


[0]
https://www.virtualbox.org/manual/ch08. ... ge-startvm
Locked

Return to “Virtual Machines”