LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (http://www.linuxquestions.org/questions/aix-43/)
-   -   Function block usage in Shell script to UnInstall Specific packages (http://www.linuxquestions.org/questions/aix-43/function-block-usage-in-shell-script-to-uninstall-specific-packages-4175434819/)

linux098 10-30-2012 05:54 PM

Function block usage in Shell script to UnInstall Specific packages
 
Hi Team,

I need to write a shell script to do the following. I'm installting software packages using an install script but, my installation fails because the machine has traces of old installations. So I need verify installed old packages (lslpp) and then uninstall the old packages (installp -u) and then continue to the install script.

Suppose my installation packages are

ABC.lic
ABC.xyz
ABC.123
ABC.rte
ABC.jrte



when I do a lsllp -l | grep 'ABC'

I'll get all the packages installed with ABC in the package name. If the reason code is 0 it means there are traces of previous installations. So before installing the new packages I need to unstall the old packages.

installp -u ABC.lic
installp -u ABC.xyz
installp -u ABC.123
installp -u ABC.rte
installp -u ABC.jrte


But my problem is not every machine will have all the above packages installed. Some machine might have only packages ABC.lic and ABC.xyz while other might have ABC.rte and ABC.jrte. or some machine might have only ABC.jrte

So I need to identify exactly what packages are installed and just uninstall only those packages. I cannot use installp -u *ABC* as that might uninstall packages related to antoher software package.

Instead of writing lengthy if else loops to find the installed software can I use an uninstall function in my script and pass the installed packages as variables.

Could anyone of you please suggest me how I can wrtie my function block and call it to unistall only specifc packages or please suggest me if there is better way to accomplish this task.

Anyhelp is greatly appreciated!

cliffordw 11-01-2012 12:19 AM

Hi there,

A few quick suggestions.

Firstly, I'd advise against using "lsllp -l | grep 'ABC'" just in case 'ABC' appears in a description rather than a fileset name somewhere. "lslpp -l '*ABC*'" avoids that.

Next you can get to the fileset names only by running:
Code:

lslpp -Lc '*ABC*' | awk 'BEGIN {FS=":"} !/^#/ {print $1}'
Lastly you can remove these one at a time with the help of xargs. Try this first to test that it produces the desired commands:
Code:

lslpp -Lc '*ABC*' | awk 'BEGIN {FS=":"} !/^#/ {print $1}' | xargs -n1 echo lslpp -u
If it works, just remove the "echo" and you're good to go.

Good luck!


All times are GMT -5. The time now is 05:36 PM.