last day (15 days later) » 

15:56
2
A: How do I setup two cron jobs to run every night at 3:00 and 3:10?

Eric CarvalhoOpen a terminal (Ctrl+Alt+T) then run: crontab -e If it asks you to select an editor, choose nano. Insert these lines at the end of the file: 0 3 * * * vboxmanage controlvm virtualpbx acpipowerbutton 5 3 * * * vboxmanage startvm virtualpbx -type headless Press Ctrl+O,Return to save the fi...

okay...I see that crontab is the cron configuration file. I have it open in the editor so I will add the lines. Thanks.
You don't have to edit /etc/crontab. Just run crontab -e to configure a cron job for the user currently logged in.
crontab -e doesn't do anything....the cursor just moves to the next line and seem to be waiting for input. I ctrl-c to get out of it.
will it work if I just add your two line to the /etc/crontab configuration? There are other similar lines there?
You'll have to put username after the *'s. Like: 0 3 * * * root vboxmanage controlvm virtualpbx acpipowerbutton. Use the same user that runs the virtual machines.
okay...done.... I will see if it works in the am. One last question. Do I need to restart the machine for those new cron jobs to be picked up or will it happen automatically?
15:56
No need to reboot. I think new jobs will be automatically detected, but just to be sure, run: sudo service cron stop, sudo service cron start.
Eric... do you mind if I edit your answer to explain exactly what I did....
I don't know if long edits to someones answer is kosher or not? OK thx.
As long as the edits enhance the posts without change their essence, that's no problem.
16:20
Eric...does cron "impersonate" the account of the person mentioned on each line? In my case, the VMs are started under my (root) username of "seths". Cron has the authority to do that? I guess I am wondering how can cron run that job under my account without having my password as well?
The cron service runs as root, and root can impersonate any user. For example, run "sudo su -" to become root, you'll have to enter your password. Then run "su - seths", root will become seths without asking for password.
OK...so one more quick question then. for the crontab...should I have put seths as the username (whcih is how i AM starting the VMs with init.d) or should I have put root. I ask because all of the other entries said root. But I put seths....I think that is correct but if you could confirm.
Actually it's not a good example...
"su - username" will ask for password when run from a non-root user, while when run by root the password will not be asked.
It depends on how vboxmanage comunicates with the virtual machines. I used vboxmanage once, and I had to run it with the same user that runs the vm. You can test it yourself. Become root and try to run some command on a VM.
If the job doesn't run from crontab try adding "DISPLAY=:0.0" near the beginning of that file.
16:44
ok...I actually think it is not going to work now. vboxmanage list runningvms shows results. sudo vboxmanage list runningvms does nothing. It does not error out but nothing is output to the console. How do I "become root"?
To simulate cron's environment run: "sudo su -", "su - seths", "vboxmanage list runningvms", if it fails run "DISPLAY=:0.0" and try "vboxmanage list runningvms" again.
If you need "DISPLAY=:0.0" to get results, add it to /etc/crontab.
 
2 hours later…
18:46
Eric...I ran those three commands in order and it did list the VMs. So running "sudo su -" changed the runtime environment to match that of cron? Any case, thanks for the help.

last day (15 days later) »