Solved

linux if statement

Posted on 2013-01-10
7
260 Views
Last Modified: 2013-01-10
trying to understand how to put together an if statement that will

first check if the rpm finds any "release"

if not "redhat-release" then output what it found

and echo that and end the if statment

what I have is

if ! rpm -qa | grep "release"



thanks.
0
Comment
Question by:atom_jelly
7 Comments
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 84 total points
Comment Utility
your question is not clear, please elaborate.
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
Comment Utility
You can have
if ! $(rpm -qa | grep -q release)
then
    echo found
fi

Open in new window

0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 166 total points
Comment Utility
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep release)
then
  echo "releases found: ${releases}
else
  echo "no releases found:
fi;
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
Comment Utility
Let me revise my code

release=$(rpm -qa | grep release)
if ! $(echo $releases | grep -q release)
then
  echo $release
else
  echo "release : $release"
fi

Open in new window

0
 
LVL 37

Assisted Solution

by:Gerwin Jansen
Gerwin Jansen earned 166 total points
Comment Utility
(a bit to quick in previous post..)

This works:
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep -q release)
then
  echo "releases found: ${releases}"
else
  echo "no releases found"
fi;

Open in new window

0
 
LVL 31

Accepted Solution

by:
farzanj earned 250 total points
Comment Utility
As per your requirements, perhaps it should be

release=$(rpm -qa | grep release)
if ! $(echo $releases | grep -iq "redhat-release")
then
  echo "Red Hat release found"
else
  echo "release : $release"
fi
0
 

Author Closing Comment

by:atom_jelly
Comment Utility
Thank you all.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now