I have an ubuntu home server running virtual box. I have virtual server running on that box that I am having problems with. For now I don't have time to troubleshoot the actual issue but I have found that restarting the server fixes the issue for at least 24 hours. So my quick fix is to restart the server each night.
Bottom line is that I want to run the following command at 3:00 am 7 days a week.
vboxmanage controlvm virtualpbx acpipowerbuttonat 3:05 each night I want to run the following command.
vboxmanage startvm virtualpbx -type headlessThe best answer will give me step-by-step instructions for getting this done from launching the console to closing the console. I want to learn more of cron and the linux infrastructure but for now I don't have the time.
Thanks so much for your help.
Seth B Spearman
** EDIT **
I want to be able to put these in place from an ssh prompt. (Don't laugh but the server doesn't have a monitor hooked up right now and it would take a fair amount of work to get it working.). But I can ssh to it at any time.
From the ssh prompt crontab does not seem to work...it just goes to the next line and seems to be waiting for more input.
I tried to install crontab from ssh using sudo apt-get install crontab but it can't find it in any repository.
So I think I will use nano and do it manually but I need to know where to put it.
ALL that to say...I am doing this from an ssh prompt...which I think doesn't matter but thought I would let you know.
Seth
2 Answers
Open a terminal (Ctrl+Alt+T) then run:
crontab -eIf 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 headlessPress Ctrl+O,Return to save the file and Ctrl+X to exit. Then run exit to close the terminal.
EDIT
This is what the OP did:
- ssh to server
sudo nano /etc/crontab <key in password>edit per Eric's recommendation but added the username that starts the VMs as follows...
0 3 * * * username vboxmanage controlvm virtualpbx acpipowerbutton 5 3 * * * username vboxmanage startvm virtualpbx -type headlessCTRL-X to close. Enter to save the crontab.
- Restart cron:
sudo service cron stopthensudo service cron start.
Drop to console
Create a bash script, one for each of the commands, (don't forget to make them executable with sudo chmod +x filename.sh) and store them in a place that cron can run them from.
sudo anacron -t 00 03 * * * /path/to/script/script1.sh
sudo anacron -t 10 03 * * * /path/to/script/script2.shEnjoy!
3