+ Post New Thread
Results 1 to 5 of 5
Scripts Thread, script to check virtual machine is running in Coding and Web Development; Im looking for a bash script i can run as a cron that will check for the existance of a ...
  1. #1

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,512
    Thank Post
    1,320
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    199

    script to check virtual machine is running

    Im looking for a bash script i can run as a cron that will check for the existance of a running process (ps x | grep 2008R2 or something like that) and if its not running, it will run the command to start the virtuualbox.

    Anyone able to knock something up for me please?

  2. #2

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,512
    Thank Post
    1,320
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    199
    Code:
    #!/bin/bash
    # Script to check if the VM is up and if not, start it.
    
    # Check for 2008R2 Virtual Machine
    
    if ping -c 1 192.168.2.30 > /dev/null
    then
      : # colon is a null and is required
    else
       echo "Virtual Machine is down, starting VM"
       VBoxHeadless -startvm 2008R2 &
    fi

  3. #3


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,688
    Thank Post
    352
    Thanked 794 Times in 714 Posts
    Rep Power
    346
    Looks fine to me.

  4. #4

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,512
    Thank Post
    1,320
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    199
    Quote Originally Posted by kmount View Post
    Looks fine to me.
    Cheers, I was just answering my own question in case anyone else was looking for an answer

  5. #5

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,859
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    You could simplify the test a bit:

    Code:
    #!/bin/bash
    # Script to check if the VM is up and if not, start it.
    
    # Check for 2008R2 Virtual Machine
    
    ping -c 1 192.168.2.30 > /dev/null || (echo "Virtual Machine is down, starting VM"; VBoxHeadless -startvm 2008R2 & )
    edit:I stole your signature test for my own, nice idea!
    Last edited by powdarrmonkey; 21st January 2010 at 10:51 PM.

SHARE:
+ Post New Thread

Similar Threads

  1. Virtual Machine connecting to domain
    By stevo1565 in forum Mac
    Replies: 2
    Last Post: 11th November 2009, 10:45 AM
  2. Script to check if app is running ...
    By pooley in forum Windows
    Replies: 4
    Last Post: 5th January 2009, 11:31 AM
  3. Replies: 5
    Last Post: 11th December 2008, 03:34 PM
  4. Check program is running regularly?
    By dave.81 in forum How do you do....it?
    Replies: 8
    Last Post: 10th September 2008, 07:03 AM
  5. Virtual Machine.... Server 03
    By kiran in forum Thin Client and Virtual Machines
    Replies: 5
    Last Post: 26th February 2007, 06:51 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •