Shell script to "rpm -e ..." in RHEL & "pkgrm ..." in Solaris

I have old versions of an agent which I would like to uninstall from
the RHEL 5 & 6 and Solaris 10 x86 servers & would like to use a
centralized automation tool to run a Shell script remotely.

Will need 2 scripts, one for RHEL & one for Solaris 10 x86:

The pseudo codes are basically:

RHEL:
=====
rpm -qa |grep ds | grep "9.00-5000"
if found, then exit script,
   else
      { /etc/init.d/ds_agent stop
        rpm -qa |grep ds
        rpm -e "what is listed in the  rpm -qa  command just above"
        rpm -ivf /var/tmp/ds-agent-9.00-5000.rpm
        /etc/init.d/ds_agent start }


Solaris:
======
pkginfo -l |grep ds | grep "9.00-5000"
if found, then exit script,
   else
      { /etc/init.d/ds_agent stop
        pkginfo |grep ds  | sed the first column parameter
        pkgrm "what is listed in the  pkginfo command just above"
        pkgadd -d /var/tmp/ds-agent-9.00-5000.rpm
        /etc/init.d/ds_agent start }
sunhuxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joseph GanSystem AdminCommented:
"pkgadd -d /var/tmp/ds-agent-9.00-5000.rpm"

In Solaris it should be

pkgadd -d /var/tmp/ds-agent-9.00-5000.pkg
simon3270Commented:
You seem to be cehcking whether the installed version is already 9.00-5000, and if not, installing that version.

For RPM, could you do:

   rpm -Uv /var/tmp/ds-agent-9.00-5000.rpm

If it is already at that level, the upgrade should do nothing.

For Solaris:

  pkginfo -l ds-agent | grep '9.00-5000'
  if [ $? -ne 0 ]; then
    pkgrm ds-agent
    pkgadd -d /var/tmp/ds-agent-9.00-5000.pkg
  fi

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunhuxAuthor Commented:
will Linux uV command upgrade majorversion ?
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Joseph GanSystem AdminCommented:
Yes, what simon3270 saying was instead of removing an old rpm and install new rpm in Linux, you can use package update comand in one go.
sunhuxAuthor Commented:
Ok, understand what  "rpm -Uv ..."  does

Can I ask for one extra favour:

to enhance the scripts such that
a) it checks if iptables is running in the RHEL/Solaris
b) if it is, then permit Tcp4120 incoming into the server &
    Tcp4118 outgoing from the server to 172.21.5.91 & .92
sunhuxAuthor Commented:
One more question:
I recall Solaris pkgadd will have problem reading a pkg file if the file
(or possibly it's directory) has sticky bit enabled : I guess /tmp has
this sticky bit on so can we say that it's best to place pkg files in
/var/tmp than in /tmp (which also will clear away files upon reboot)?
Joseph GanSystem AdminCommented:
/tmp has sticky bit on because it allows everyone read/write to it, not stopping you to run pkgadd. But put pkg in /var/tmp is best prectise. Yes, by default files under /tmp will be cleaned up on boot, again you could disable this if you want.
sunhuxAuthor Commented:
Thanks.  What are those commands to permit iptables rules indicated above?
simon3270Commented:
The Solaris ones need some setup (you are better of searching for examples, and modifying them to your purposes).  You need to use the ipf  service.

For RedHat, iptables will be what you want - again, searching for examples may be your best bet.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.