Solved

linux if statement

Posted on 2013-01-10
7
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

Assisted Solution

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

Assisted Solution

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

Open in new window

0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 166 total points
ID: 38763199
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep release)
then
  echo "releases found: ${releases}
else
  echo "no releases found:
fi;
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
ID: 38763217
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 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 166 total points
ID: 38763260
(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
ID: 38763270
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
ID: 38763317
Thank you all.
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

635 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