Need a if else check startement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a if else check startement
# 1  
Old 07-10-2018
Need a if else check startement

need to remove some software on esx server if available

like this

Code:
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




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 07-10-2018 at 11:09 AM.. Reason: Added CODE tags.
# 2  
Old 07-10-2018
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
# 3  
Old 07-10-2018
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?
# 4  
Old 07-10-2018
So your script might start:-
Code:
#!/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
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 07-15-2018
I tried running it and even though

Code:
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


Code:
#!/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?

Last edited by Scrutinizer; 07-14-2018 at 11:44 PM.. Reason: code tags
# 6  
Old 07-16-2018
You could try this:

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

This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check

echo "2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180 2012-12-29--13.3637 2012-12-30--13.7091" the set of numbers i provided above is separated by spaces. how do i count how many sets there are? i tried: echo "2012-12-26--14.8224 2012-12-27--14.2898 2012-12-28--14.9180... (5 Replies)
Discussion started by: SkySmart
5 Replies

2. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

3. Shell Programming and Scripting

check in and check out comments

Hi Do you know how can I get all check in and check out comments for a period of time with Surround SCM CLI ---------- Post updated at 02:00 AM ---------- Previous update was at 01:56 AM ---------- Do you have NAnt tasks that allow us to access Evolution from an NAnt build script? (0 Replies)
Discussion started by: saku
0 Replies

4. Shell Programming and Scripting

check if it's there

Dear, I want to check if the file in the if code is there, but I don't know how to do it? if Can someone assist me please? Thanks! kopie() { echo " Geef de naam van bestand + plaats vanwaar gekopieerd moet worden en waarnaar : " echo -n " Plaats : " read plaats ... (7 Replies)
Discussion started by: yadeki
7 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

7. Shell Programming and Scripting

check whether the value changes or not!

HI all, I need help in writing a shell script for the following logic I have a file abc.txt and it contains a number x. The number in the file abc.txt changes every day. I need to develop a shell script which on every run checks the number in the file and increments a variable by 1 if a... (4 Replies)
Discussion started by: marcus_kosaman
4 Replies

8. UNIX for Dummies Questions & Answers

is there any way to check if some ip is taken ?

hello is there any tool in unix that will indicate if some ip is already taken by other machine? (4 Replies)
Discussion started by: umen
4 Replies

9. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question