Need help with pattern matching to list missing packages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with pattern matching to list missing packages
# 1  
Old 03-08-2016
Need help with pattern matching to list missing packages

I have wrote this small program to check for installed and missing packages in LINUX (RHEL x86_64)

For now it perfectly prints all the installed and missing packages however I want that it loops through to the end (in either case) and
list all packages however if one or more packages are found missing then program should terminae

here is program

Code:
#echo ""
echo "Checking for installed packages...please wait"
echo ""

for  PACKAGE in binutils.x86_64 compat-libstdc++-33.x86_64  glibc-common.x86_64 glibc.x86_64 glibc-devel.x86_64 \
glibc-headers.x86_64  ksh.x86_64 libaio.x86_64 libaio-devel.x86_64 libgcc.x86_64  libstdc++.x86_64 libstdc++-devel.x86_64 make.x86_64 \
  compat-libcap1.x86_64 gcc.x86_64 gcc-c++.x86_64 glibc-devel.x86_64  libstdc++.x86_64 libstdc++-devel.x86_64 sysstat.x86_64
do
if yum list installed $PACKAGE >/dev/null 2>&1;
then
echo "$PACKAGE is installed"
else
echo "$PACKAGE not installed"
fi

done
Moderator's Comments:
Mod Comment code tags please! they help us to help you

Last edited by jim mcnamara; 03-08-2016 at 06:26 PM.. Reason: code tags
# 2  
Old 03-08-2016
Code snipped:
Code:
if yum list installed $PACKAGE >/dev/null 2>&1;
then
  echo "$PACKAGE is installed"
else
  echo "$PACKAGE not installed"
  exit 1
fi

The exit 1 statement causes the loop and the script both to terminate. Also the return code will be a failure. Is this what you meant?
# 3  
Old 03-08-2016
no, i think exit 1 will end the loop as soon as first occurance of 'non installed' pacakge will be encountered. I dont want loop to end - #i want it to complete until it checks last package mentioned in for loop and thn exit if found any missing package.
# 4  
Old 03-08-2016
hi,
Code:
forpackage in <list of packages>
do
   if <installed>
   then <package ok>
   else <nogo for package>; nogo=1
   fi
done
test $nogo -ge 1 && exit 1

why wouldn't you make the script to stop as soon as it detects a missing package ?
# 5  
Old 03-09-2016
Because than there may b last package missing - so i want to loop through all of them then list those which are missing - so that we can go back to Unix support and ask them to install the missing packages in one request, the program must also exit after listing missing packages. If none found missing than program should continue

Thanks
# 6  
Old 03-09-2016
Why don't you yum list all installed packages and then check against your list? Would have the advantage running yum just once instead of once per package.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Matching Columns - Am I missing something?

I am using awk to match columns and output based on those matches. For some reason it is not printing matching columns, am I missing something? Operating system - windows with cygwin. Command that I am using: sed 's/]*,]*/,/g' $tempdir/file1 > $tempdir/file1.$$ && awk -F, 'FNR==NR{f2=$2... (7 Replies)
Discussion started by: dis0wned
7 Replies

2. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

4. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

5. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

6. Shell Programming and Scripting

How to cut string and find missing pattern?

i have list in file named sample.txt eg i want to cut the 3rd and 4th character i.e. 01,02,03....,24(max length is 24) and i want to find the missing sequence .and display them i.e. (15 Replies)
Discussion started by: sagar_1986
15 Replies

7. UNIX for Dummies Questions & Answers

Script to list non matching files using pattern

Hi, I am trying to write a script that list down all the files that do not match the pattern My pattern will be like this "*.jpg|*.xml|*.sql". This pattern will be stored in a file. The script need to read this pattern from the file and delete the files that does not match this pattern. It... (7 Replies)
Discussion started by: meenavin
7 Replies

8. Shell Programming and Scripting

sed - matching pattern one but not pattern two

All, I have the following file: -------------------------------------- # # /etc/pam.d/common-password - password-related modules common to all services # # This file is included from other service-specific PAM config files, # and should contain a list of modules that define the services... (2 Replies)
Discussion started by: RobertBerrie
2 Replies

9. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question