+ 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
    4,747
    Blog Entries
    6
    Thank Post
    1,015
    Thanked 427 Times in 272 Posts
    Rep Power
    141

    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. IDG Tech News

  3. #2

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    4,747
    Blog Entries
    6
    Thank Post
    1,015
    Thanked 427 Times in 272 Posts
    Rep Power
    141
    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

  4. #3


    Join Date
    Feb 2007
    Location
    Northamptonshire
    Posts
    4,431
    Thank Post
    327
    Thanked 726 Times in 654 Posts
    Rep Power
    201
    Looks fine to me.

  5. #4

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    4,747
    Blog Entries
    6
    Thank Post
    1,015
    Thanked 427 Times in 272 Posts
    Rep Power
    141
    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

  6. #5

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,855
    Thank Post
    412
    Thanked 774 Times in 647 Posts
    Rep Power
    168
    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 11: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, 11:45 AM
  2. Script to check if app is running ...
    By pooley in forum Windows
    Replies: 4
    Last Post: 5th January 2009, 12:31 PM
  3. Replies: 5
    Last Post: 11th December 2008, 04: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, 07: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
  •