Hi,
I'm very new to bash scripts (and linux in general) but am trying to run a script on a host to determine if any VirtualBox virtualmachines are running.
The relevant part of the script is:
Code:
if [ 'sudo -u virtualboxuser VBoxManage list runningvms | wc -l' != "0" ]
then
echo "VirtualMachine is running" >> $logfile
echo $(sudo -u virtualboxuser VBoxManage list runningvms | wc -l) >> $logfile
fi
Unfortunately, I always seem to enter the 'if' statement even if no virtual machines are running. I'm piping the output to a logfile, and looking at my logfile I can see that the result of the line
Code:
echo $(sudo -u virtualboxuser VBoxManage list runningvms | wc -l) >> $logfile
is 0.
Please can anyone tell me why the 'if' statement is still being executed? Or is there a better way to determine if any virtualmachines are running?