Operating System - HP-UX
1833464 Members
2629 Online
110052 Solutions
New Discussion

shell script to check if patch is installed or not

 
SOLVED
Go to solution
Adi_7
Frequent Advisor

shell script to check if patch is installed or not

hi
I need to write a script which checks if a particular patch is installed or not.
I have written something like
if grep $input swlist1.out > /dev/null 2>&1
then
echo "installed"
else
echo "not installed"
fi

The output of swlist command is stored in the file swlist1.out

I'm getting this error.
ERRNO=25
LINENO=2
MAILCHECK=600
OPTIND=1
PPID=26004
RANDOM=24630
SECONDS=0
TMOUT=0
Please enter the name of the application
perl
You entered perl
./hpscript2.ksh[7]: swlist: not found
software perl not installed

Please help.
8 REPLIES 8
Rita C Workman
Honored Contributor

Re: shell script to check if patch is installed or not

Why not just a simple line like:

swlist -l fileset -a state | grep PH

This will tell you if it's on the box....and if it's configured or not.

You could output to a file if you want....by just ending with > to-this.file

Just a simple thought,
Rita
Brian Bergstrand
Honored Contributor

Re: shell script to check if patch is installed or not

You have an error in your script.

It should be (ignore line wraps):

if [ `grep $input swlist1.out > /dev/null 2>&1` -eq 0 ]; then
echo "installed"
else
echo "not installed"
fi

Of course Rita's suggestion is much easier.

HTH.
Adi_7
Frequent Advisor

Re: shell script to check if patch is installed or not

Hi Rita,
Thanks for your reply.
swlist -l fileset -a state | grep PHCO_23083
This command gives if that patch is installed or not.
But what if I have to check if a particular software(application) is installed or not?

Thanks again.
Brian Bergstrand
Honored Contributor
Solution

Re: shell script to check if patch is installed or not

To grep for an app, just change the arg to grep. For instance to see if CDE is installed.

swlist -l product | grep -i cde

You could generalize this as a shell script if you wanted too.

#!/bin/sh

if [ -z "$1" ]; then
echo "arg needed"
exit 1;
fi

swlist -l product | grep -i "$1"

Save this where you want, make it executable and then run. E.G.

/usr/local/sbin/myswchk.sh CDE

HTH.
Adi_7
Frequent Advisor

Re: shell script to check if patch is installed or not

Actually I'm trying to write a tiny script that will determine whether a particular software application is installed. This script should take as its input (either as a command line argument or hard coded) the name of the application. Its output should be something like "Installed" or "Not Installed".


Adi_7
Frequent Advisor

Re: shell script to check if patch is installed or not

hey brian,
thanks a lot.Your script did work.
Brian Bergstrand
Honored Contributor

Re: shell script to check if patch is installed or not

Great, glad we could help. How about handing out some points?

BTW, my C coding slipped in by accident. The exit statement should not end in a semi-colin.

exit 1;

Should just be

exit 1
Adi_7
Frequent Advisor

Re: shell script to check if patch is installed or not

actually It didnt make any difference.
But thanks for reminding.