Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 acpipowerbutton

at 3:05 each night I want to run the following command.

vboxmanage startvm virtualpbx -type headless

The 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 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.


share|improve this question
up vote 4 down vote accepted

Open 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 file and Ctrl+X to exit. Then run exit to close the terminal.

This is what the OP did:

  1. ssh to server
  2. sudo nano /etc/crontab <key in password>
  3. 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 headless  
  4. CTRL-X to close. Enter to save the crontab.

  5. Restart cron: sudo service cron stop then sudo service cron start.
share|improve this answer
okay...I see that crontab is the cron configuration file. I have it open in the editor so I will add the lines. Thanks. – Seth Spearman Jun 1 '13 at 15:30
You don't have to edit /etc/crontab. Just run crontab -e to configure a cron job for the user currently logged in. – Eric Carvalho Jun 1 '13 at 15:32
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. – Seth Spearman Jun 1 '13 at 15:33
will it work if I just add your two line to the /etc/crontab configuration? There are other similar lines there? – Seth Spearman Jun 1 '13 at 15:34
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. – Eric Carvalho Jun 1 '13 at 15:38

Drop to console

Create a bash script, one for each of the commands, (don't forget to make them executable with sudo chmod +x and store them in a place that cron can run them from.

sudo anacron -t 00 03 * * * /path/to/script/

sudo anacron -t 10 03 * * * /path/to/script/


share|improve this answer
10 03 is mm hh so 3.05pm would be 05 15 – SimplySimon Jun 1 '13 at 14:25
can you tell me a place that "cron can run from". – Seth Spearman Jun 1 '13 at 15:13
Sure, cron will run as root, so any place that has the root group ownership over. When you use ls you can view the owner and group permissions. – RGS Jun 1 '13 at 15:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.