PDA

View Full Version : Simple bash script help



mad_max0204
December 15th, 2010, 04:52 PM
Guys,

I'm trying to make simple bash script that checks if vmware VMs are running and if they are not then start them.
Since I use 4 VMs it can be done by reading output of "vmrun list" which is a list of running VMs and looks something like this:

Total running VMs: 2
/home/VM1.vmx
/home/VM2.vmx

Thanks for any help

Max

j.netbreed
December 15th, 2010, 10:44 PM
something like...



ps ax | grep [m]yvmwareprocessname
if [ $? = 1 ]; then
/path/to/run/vmware


important to keep the parentheses around the first letter of the process name so as not to return the grep process

Arndt
December 15th, 2010, 11:51 PM
something like...



ps ax | grep [m]yvmwareprocessname
if [ $? = 1 ]; then
/path/to/run/vmware


important to keep the parentheses around the first letter of the process name so as not to return the grep process

There is 'pgrep', too.

aeronutt
December 16th, 2010, 12:03 AM
something like...



ps ax | grep [m]yvmwareprocessname
if [ $? = 1 ]; then
/path/to/run/vmware


important to keep the parentheses around the first letter of the process name so as not to return the grep process

I learn a new trick every day!

mad_max0204
December 16th, 2010, 12:40 AM
EDIT: Scratch that it does work.

What is 'pgrep' and what would be the difference ?

j.netbreed
December 16th, 2010, 08:20 AM
man pgrep
basically pgrep looks up processes, you could change my above example to...


pgrep vmwareprocessname
if [ $? = 1 ]; then
/path/to/vmwarerunprog

...at its rawest