Jump to content

Recommended Posts

Posted

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? :)

Posted
#!/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

Posted (edited)

You could simplify the test a bit:

 

#!/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!

Edited by powdarrmonkey

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...