[Solved] VBoxManage script runs manually but not from cron

Discussions related to using VirtualBox on Linux hosts.
Post Reply
NginUS
Posts: 25
Joined: 15. Mar 2017, 05:55

[Solved] VBoxManage script runs manually but not from cron

Post by NginUS »

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.

Thanks in advance.
Last edited by NginUS on 13. Dec 2018, 19:45, edited 1 time in total.
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: VBoxManage script runs manually but not from cron

Post by socratis »

NginUS wrote:VirtualBox version 5.1.38_Ubuntu r122592.
1) That's an old VirtualBox version, but most importantly 2) This is a fork of the official VirtualBox.

You can either ask in their forums for help, or completely remove/uninstall/delete/purge their version and install the official version from the Linux Downloads section of VirtualBox.
NginUS wrote:But from cron it fails somehow.
Because it's not running under your account. VirtualBox VMs are registered and run on a per-user basis, not on a per-computer basis. A lot of people think that 'root' has more powers but when it comes to VirtualBox it can't even see the user's VMs.
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.
NginUS
Posts: 25
Joined: 15. Mar 2017, 05:55

Re: VBoxManage script runs manually but not from cron

Post by NginUS »

For future reference this change solved the issue:

Code: Select all

#!/bin/bash
VBoxManage startvm VMName --type=separate
sleep 15
VBoxManage controlvm VMName setvideomodehint 1440 900 32
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: [Solved] VBoxManage script runs manually but not from cron

Post by socratis »

So, the delay was the solution? You were trying to adjust the screen resolution before the VM was even running in a sense?
NginUS wrote:But from cron it fails somehow.
i should have asked you how it failed exactly, it might have revealed the error source...
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.
NginUS
Posts: 25
Joined: 15. Mar 2017, 05:55

Re: [Solved] VBoxManage script runs manually but not from cron

Post by NginUS »

No, that became apparent it was needed after I got it working. What fixed it was removing the path to the VM & just using its name after VBoxManage during that command.
Last edited by socratis on 14. Dec 2018, 00:37, edited 1 time in total.
Reason: Removed unnecessary verbatim quote of the whole previous message.
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: [Solved] VBoxManage script runs manually but not from cron

Post by socratis »

D'oh! :shock:
I should have seen that. You just start it by using the VM's registered name, not the actual path...
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.
Post Reply