LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-03-2018, 03:40 AM   #1
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Rep: Reputation: Disabled
Unhappy Crontab gives errors when running Virtualbox as type gui in shell script


Hi guyz,

Im new to linux and i have been experiencing problems . I have the following shell script:

Code:
#! /bin/bash

export DISPLAY=:0.0
gnome-terminal -e "/usr/lib/virtualbox/VBoxManage startvm WinXp --type gui" &> /tmp/crontab3.output
when i run this script manually, WinXP vm starts successfully without any issues, but when I try to run the script using cron nothing happens and i dont even get errors. I know crontab works fine because i have tested it with a script that doesnt execute any gui application. with that said, i initially had my script written like this:

Code:
#! /bin/bash

/usr/lib/virtualbox/VBoxManage startvm WinXp --type gui
running this manually would work, but running it from cron would only work as headless type, changing the type to gui, i get the following error in cron.output:

Code:
VBoxManage: error: The virtual machine 'WinXp' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
Waiting for VM "WinXp" to power on...
I have tried all solutions there are on the internet but no success, hence i resorted to the first script. Can you guys please help me to get this to work? I've been trying for almost a month now.

Im running:
Centos 6.3 final (been trying to update using "yum update" but i get all sort of errors. Any other ways of updating?)
kernel 2.6.32-279.5.2.el6.x86_64
GNOME 2.28.2

Virtualbox 5.2

my crontab looks like this:

Code:
SHELL=/bin/bash
PATH=/usr/local/sbin:usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/data/Dante
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
#  37 14 26  4  4 /data/Dante/sedtry4.sh &> /tmp/cron.output
  27 9 3 6 7 "/data/Dante/runvbox2.sh" &> /tmp/cron.output
Your help will be highly appreciated.

Last edited by dante_t; 06-03-2018 at 07:47 AM.
 
Old 06-03-2018, 07:07 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
If you want to run a GUI application, you need a complete environment with lots of settings which enables the GUI application to run. You, as user logged in into a terminal do have such an environment set up for you. Crontab does not, which is the reason for failure.

Now it strikes me as counter intuitive to run a GUI application from contab. The normal thing to do would be to start a vm from within crontab so you can connect to it over ssh or vnc. What are you trying to achieve anyway?

jlinkels
 
Old 06-03-2018, 07:29 AM   #3
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
If you want to run a GUI application, you need a complete environment with lots of settings which enables the GUI application to run. You, as user logged in into a terminal do have such an environment set up for you. Crontab does not, which is the reason for failure.

Now it strikes me as counter intuitive to run a GUI application from contab. The normal thing to do would be to start a vm from within crontab so you can connect to it over ssh or vnc. What are you trying to achieve anyway?

jlinkels
Hi jlinkels, thank you for your response.

I have files im downloading and processing using linux, and then further processing and displaying of results happens in WinXp vm. I can do all this manually without any issues but the problems is, i have to do this everyday and it takes time. So I'm automating the whole process. I start with:
1. downloading files,
2. process the files and put the output files in a shared folder,
3. automatically run winxp vm using Virtualbox and then
4. process and display the results.

steps 1, 2 & 4 are sorted (automation done), the issue is step 3. I cannot run vm as headless because there are results I need to display on the VM screen. all I need is vm to open when crontab tells it to.

I hope this helps.

Regards
 
Old 06-03-2018, 07:56 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
I see. But it is a strange approach. I would not know how to handle the startup of a VM with GUI from within cron.

The more sound approach would be to have XP running in a VM, and build a schedule in XP to start processing results when data is available, and display it after that.

jlinkels
 
Old 06-03-2018, 09:49 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,067

Rep: Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368
Welcome to LinuxQuestions.

I agree that it is a strange approach but can be done like in the following link. As noted DISPLAY=:0.0 needs to be in the cron command line and not in the script.

Also note that it looks like you added the line to /etc/crontab which is for system tasks and probably should be in your users cron (crontab -e) due to different environment variables or maybe add them to your script.

In addition day of month and day of week are either or so the job will run if either match.

https://www.linuxquestions.org/quest...-a-4175629930/
 
1 members found this post helpful.
Old 06-03-2018, 11:30 AM   #6
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
I see. But it is a strange approach. I would not know how to handle the startup of a VM with GUI from within cron.
As I have already mentioned, I am new to this, so the only way I thought could work is this way. Please help if there are other ways you can think of.

Quote:
The more sound approach would be to have XP running in a VM, and build a schedule in XP to start processing results when data is available, and display it after that.
That is exactly what I am doing. I want to turn on the vm so that processes scheduled in winxp can run. Those processes cannot run if the vm is not running. Or maybe im wrong. Can the vm auto on itself?

Last edited by dante_t; 06-03-2018 at 11:38 AM.
 
Old 06-03-2018, 11:36 AM   #7
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Welcome to LinuxQuestions.
Hi Michael, thank you.

Quote:
=I agree that it is a strange approach but can be done like in the following link. As noted DISPLAY=:0.0 needs to be in the cron command line and not in the script.


Also note that it looks like you added the line to /etc/crontab which is for system tasks and probably should be in your users cron (crontab -e) due to different environment variables or maybe add them to your script.

In addition day of month and day of week are either or so the job will run if either match.
Im totally lost now, can you please put what you are saying as commands I can execute on my system?

Quote:
Originally Posted by
[url
https://www.linuxquestions.org/questions/slackware-14/the-virtual-machine-has-terminated-unexpectedly-during-startup-because-of-signal-6-a-4175629930/[/url]
I'm currently not at home, I will have at the link later when I get home. Thank you.

Last edited by dante_t; 06-03-2018 at 11:37 AM.
 
Old 06-03-2018, 12:49 PM   #8
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
Quote:
Originally Posted by dante_t View Post
That is exactly what I am doing. I want to turn on the vm so that processes scheduled in winxp can run. Those processes cannot run if the vm is not running. Or maybe im wrong. Can the vm auto on itself?
Just don't turn off the VM. If you have a schedule in XP, the task will only run at the scheduled time. Other than that, Windows does not use much resources. AFAIK schedules are not executed in Windows when the machine is power save mode so you might want to disable Windows power save mode.

If you don't want Windows to run, start the VM without display. VBox can run a Windows machine without display. You can power down, save and resume the VM from the command line. Then use VNC to look onto the Windows screen. VBox is built so that you can use VNC to look at the screens of VMs which do not have a display.

Alternatively Michaelk's solution might work as well. The options I gave you use VBox and VMs fully as designed.

jlinkels
 
1 members found this post helpful.
Old 06-03-2018, 02:08 PM   #9
X-LFS-2010
Member
 
Registered: Apr 2016
Posts: 423

Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
Now it strikes me as counter intuitive to run a GUI application from contab. The normal thing to do would be to start a vm from within crontab so you can connect to it over ssh or vnc. What are you trying to achieve anyway?
jlinkels
yea. many cronjobs are text based (shell commands).

keep your text based jobs running text mode running from shell (no gui)

perhaps use a desktop app for anacron or whatever for jobs that the desktop itself (gnome) support only graphically (written in the desktop language not as text commands)
 
Old 06-03-2018, 06:01 PM   #10
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
In the cron entry set the shell.

***** SHELL=/bin/bash

In the script set an environment.

source $HOME/.bashrc
 
Old 06-04-2018, 04:47 PM   #11
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hi guyz, thank you for your responses. I will not be switching vm on and off everytime. In case of power failure, the system reboots itself and once it does, i want WinXp vm to boot up and run as well. how can i achieve that if I dont do it this way?
 
Old 06-04-2018, 07:41 PM   #12
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,191

Rep: Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039Reputation: 1039
It is possible according to this description. https://askubuntu.com/questions/4046...y-when-booting

jlinkels
 
Old 06-05-2018, 06:50 AM   #13
dante_t
LQ Newbie
 
Registered: Jun 2018
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
It is possible according to this description. https://askubuntu.com/questions/4046...y-when-booting

jlinkels
Hi jlinkels, this is what i have tried initially. followed every step but when the system reboots the vm doesnt start and i dont know how to check what might have gone wrong.
 
Old 06-05-2018, 10:37 AM   #14
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
You could try #10. That will permit the vmware gui to run from cron.
 
Old 06-05-2018, 10:47 AM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 20,067

Rep: Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368Reputation: 3368
Have you tried my suggestion?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] systemd service type for running a shell script containing a pipe genogebot Linux - Server 4 06-17-2016 08:42 PM
unable to scp files while running shell script through crontab idhillon77 Ubuntu 4 06-15-2012 10:59 AM
Shell Script not Running from Crontab venkatramanj SUSE / openSUSE 3 01-13-2010 05:15 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
Shell script running via crontab problem. thetruethugg Linux - Software 13 12-19-2003 08:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration