need to remove some software on esx server if available
like this
if (esxcli software vib list | grep -i net-mst) is available
then
remove
esxcli software vib remove -n net-mst
done
then
esxcli software profile update -d /vmfs/volumes/deport.zip -p profile
done
then
run /tmp/upgrade.sh &
---------- Post updated at 06:55 AM ---------- Previous update was at 06:28 AM ----------
anyone can provide this in bash format?
thanks
This look a little like a shell script, in which case i would say that you finish an if...then... whith a fi but your condition for the if needs to be fixed somewhat.
What does esxcli software vib list | grep -i net-mst
give you?
Would the output from esxcli software vib list | grep -ic net-mst
be better or perhaps you just need to test the return code of esxcli software vib list | grep -qi net-mst
where zero is successful match and 1 is a failure to match. Return code 2 is an error.
I'm not sure that the trailing & will be useful either. It will put that command into the background, so you don't know (without looking) when it has finished.
Do these suggestions/questions help?
Robin
very nice.
yes esxcli software vib list | grep -ic net-mst
does give an output of 1 when available
---------- Post updated at 07:07 AM ---------- Previous update was at 07:06 AM ----------
how do I put that together in bash?
So your script might start:-
#!/bin/bash
echo "$(date) : This is the start"
if [ $(esxcli software vib list | grep -ic net-mst) -eq 1 ]
then
echo "$(date) : Software found"
esxcli software vib remove -n net-mst
esxcli software profile update -d /vmfs/volumes/deport.zip -p profile
run /tmp/upgrade.sh
else
echo "$(date) : Software not found"
fi
echo "$(date) : This is the end"
Obviously completely untested and I'm guessing at what you actually might be trying to do.
Does that help? If the condition matches, it runs the next three statements after the then in sequence until the else statement. Failing the test means it runs the echo statement. Either way, the control continues after the fi
Robin
1 Like
I tried running it and even though
esxcli software vib list | grep -ic net-mst -eq 1
It says
Software not found"
any idea?
---------- Post updated at 03:58 PM ---------- Previous update was at 03:53 PM ----------
trying to make this to work
#!/bin/bash
echo "$(date) : This is the start"
if [ $(esxcli software vib list | grep -ic net-mst) -eq 1 ]
then
echo "$(date) : Software found"
esxcli software vib remove -n net-mst
esxcli software profile update -d /vmfs/volumes/depot.zip -p profile
cp -R /vmfs/volumes/volname/dirname /tmp
chmod +x /tmp/dirname/update.sh
run /tmp/upgrade.sh &
else
echo "$(date) : Software not found"
fi
echo "$(date) : This is the end"
Can you correct please?
---------- Post updated 07-15-18 at 09:37 AM ---------- Previous update was 07-14-18 at 03:58 PM ----------
ok trying to do more modifuications
I need another check
esxcli hardware platform get | grep -i Product
output is like this
Product Name: Proliant BL460c Gen8
or could be
Product NAme: Proliant BL460c Gen9
But it could be Gen7 or
I need a check that if its Gen9
then
do
esxcli software profile update -d "/vmfs/volumes/vol1/depot1.zip" -p depot
or if its not Gen9
or if its Gen8 or Gen7
do
esxcli software profile update -d "/vmfs/volumes/vol1/depot2.zip" -p depot2
any idea?
You could try this:
#!/bin/bash
echo "$(date) : This is the start"
if [ $(.esxcli software vib list | grep -ic net-mst) -eq 1 ]
then
echo "$(date) : Software found"
esxcli software vib remove -n net-mst
PN=$(esxcli hardware platform get | grep -i Product)
case $PN in
*Gen9)
echo "$(date) : Gen 9 detected"
esxcli software profile update -d /vmfs/volumes/vo1/depot1.zip -p depot
cp -R /vmfs/volumes/volname/dirname /tmp
chmod +x /tmp/dirname/update.sh
run /tmp/upgrade.sh &
;;
*Gen[78])
echo "$(date) : Gen 7/8 detected"
esxcli software profile update -d /vmfs/volumes/vo1/depot2.zip -p depot2
;;
*)
echo "$(date) : unknown version: $PN"
;;
esac
else
echo "$(date) : Software not found"
fi
1 Like