Operating System - HP-UX
1829413 Members
1161 Online
109991 Solutions
New Discussion

Re: automation installation of package

 
tempsample
Frequent Advisor

automation installation of package

Hi

 

we have to upgrade raid manager in nearly 600 servers.

 

There is no centralized or NFS server.

 

but from NIM server ,I can log in to all 600 servers.

 

manuall installation for all 600 hosts requires more time.

 

in for loop i can add for i in hostname

 

and make a script.

 

but i have to automate the full process.

 

 

such thing like

 

taking a copy of HORCM file.

 

 

stop HORCM service.

uninstalling raid manager

 

then installing raid manager.

then start HORCM service.

 

 

i would need a help  and idea , how to write a script for all steps.

 

18 REPLIES 18
tempsample
Frequent Advisor

Re: automation installation of package

i would like to add my thoughts ,

 

for i in hostname1 hostname 2

 

do

 

stop horcm services

 

then

check if horcm servcies are stopped 

 

if not exit

 

cp -ip backup of horcm configuration

 

then

 

uninstall raidmanager

 

then run raidqry -v

 

then check if raid manager is uninstalled successfully.

 

thenn

 

 

iinstall new version of raid manager

 

then run raidqry to confirm if raid manager is updated

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

You may just want to develop a script that works on a machine and then sends mail on the status.

Once you have that script, copy it to all the machines and start the script with nohup and in the background and you wouldn't need to stay connected.

tempsample
Frequent Advisor

Re: automation installation of package

hi Dennis,

 

thanks for the info.

 

Can you help me in sharing the sample.

 

so that i can develop the remaining the part and test.

 

 

 

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>Can you help me in sharing the sample?

 

Sorry, I don't have one.

You should start with your outline of the steps above.

Take what you do manually and put in a script with checking at each step.

tempsample
Frequent Advisor

Re: automation installation of package

Hi Dnnis,

 

Thanks for the respose.

 

i have to started to create the script,but i have doubt in the below script.

 

as first step, I am taking backup of /etc/horcm0.conf and /etc/horcm1.conf firl.

 

#!/usr/bin/sh -x

 

WORKDAY=`date +%Y%m%d`

echo "#ls -ltr /etc/horcm?.conf  | grep -c ${WORKDAY}"
ls -ltr /etc/horcm?.conf  | grep -c ${WORKDAY}


RTNSTR=`ls -ltr /etc/horcm?.conf  | grep -c ${WORKDAY}`

if [ ${RTNSTR} = 1 ]; then
  echo "/etc/horcm0.conf  and /etc/horcm1.conf today's backup already created."
  echo "return 0"
  RTNCODE=0
else
  echo "#cp -p /etc/horcm1.conf  /etc/horcm0.conf_${WORKDAY}"


  cp -p /etc/horcm?.conf /home/tmp/raidmgr/log/horcm?.conf_${WORKDAY}   

 

  if [ $? -ne 0 ]; then
    echo "\nERROR. found."
    echo "Cannot backup /etc/horcm0.conf ."
    echo "return 1"
    RTNCODE=1
  else
    echo "\n Copy OK."
    echo "return 0"
    RTNCODE=0
  fi
fi

echo "\n End  : `date +\"%Y/%m/%d %H:%M:%S\"`"
echo "------------------------------------------------------------"

 

echo "#cp -p /etc/horcm1.conf  /etc/horcm0.conf_${WORKDAY}"


  cp -p /etc/horcm?.conf /home/tmp/raidmgr/log/horcm?.conf_${WORKDAY}  

 

1.how i can take backup of two horcm files --> horcm0.conf and horcm1.conf.

 

 

tempsample
Frequent Advisor

Re: automation installation of package

Hi,

 

Actually there are four files,

 

ls horcm*
horcm.conf   horcm0.conf  horcm1.conf  horcmgr

 

but i have to take backup only for /etc/horcm0.conf and /etc/horcm1.conf

 

how can i edit in the script ??

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>RTNSTR=`ls -ltr /etc/horcm?.conf | grep -c ${WORKDAY}`

 

I would recommend using the more modern $() syntax:

RTNSTR=$(ls -ltr /etc/horcm?.conf | grep -c ${WORKDAY})

 

>if [ ${RTNSTR} = 1 ]; then

 

Since this is a number, you should use the -eq operator:

if [ ${RTNSTR} -eq 1 ]; then

 

>1. how I can take backup of two horcm files --> horcm0.conf and horcm1.conf.

> cp -p /etc/horcm?.conf /home/tmp/raidmgr/log/horcm?.conf_${WORKDAY}

 

This won't replace the value of the "?" on the left to the "?" on the right.  You need a loop:

(( failed = 0 ))

for file in /etc/horcm?.conf; do

   base=${file##*/}  # basename

   cp -p $file /home/tmp/raidmgr/log/${base}_${WORKDAY}

   if [ $? -ne 0 ]; then

      # you can either count the failures or copy your existing error check

      (( failed += 1 ))

   fi

done

tempsample
Frequent Advisor

Re: automation installation of package

Hi Deenis,

 

Thanks for the response.

 

I will try to test as per your suggestion.

 

I have more doubt,

 

I am trying to view the output ,while running the script and ouptput has to appened to log file.

 

echo "/etc/horcm0.conf today's backup already created." >> ${BKP2LOG}

 

but when i run sh -x, i am able to view the output,but when i run with sh ,i am not able to view.

 

so currently ,I am using as below..

 

echo "/etc/horcm0.conf today's backup already created." >> ${BKP2LOG}   ----> this will be in log file

echo "/etc/horcm0.conf today's backup already created."  ---> I can screen in terminal

 

is this is the correct way ??

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>is this is the correct way?

 

Yes, you can do that with two echoes.  Or you can simply put the script in the background and tail -f the logfile.

tempsample
Frequent Advisor

Re: automation installation of package

HI Dennis

 

I got it.

 

currently i am successful in the below steps.

 

1.checking if horcm0.conf andhorcm1.conf exists or not .

2.stopping horcm services

3.making new dir in /opt/HORCM for HORCM dir backup.

4.copying files from /opt/HORCM to /opt/HORCM_old

 

 

now my 5th  steps is,

 

 

need to uninstall horcm.

 

cat -n srctestck.sh
     1  #!/usr/bin/ksh
     2  SRCDIR=/home/testuser/cpdir

     3  WRKDIR=pwd
     4  cd ${SRCDIR}  ----> here it will go to /home/testuser/cpdir
     5
     6  if [${SRCDIR}==${WRKDIR}];
     7  echo "i am in ${SRCDIR}"
     8  else
     9  echo "i am in some other path"
    10  exit 0
    11  fi

 

now i need to check,if both the dir are same ,if it is same execute the next step.

 

but i am not able to export WRKDIR=pwd

 

both WRKDIR and SRCDIR should be same.i am checking here if i am currently in /home/testuser/cpdir.

 

how can i export the current working dir ?

Patrick Wallek
Honored Contributor

Re: automation installation of package

To set the output of a command as the value of a variable you use the $() syntax around the command. 

 

For your current needs do:

 

WRKDIR=$(pwd)

tempsample
Frequent Advisor

Re: automation installation of package

Hi Patrick,

 

I got it.

 

WRKDIR=$(pwd)

 

or

 

WRKDIR=${pwd}

 

do both syntax are correct ??

 

since both syntax are working fine.

tempsample
Frequent Advisor

Re: automation installation of package

Hi,

 

after testing,iam facing one more problem.

 

my requirement is I need to uninstall horcm manager.

horcmuninstall.sh is present in /opt/HORCM.

 

so if i am runiing the above from other path,i have to move to /opt/horcm.

 

so i am exporting values as

 

SRCDIR=/opt/HORCM
WRKDIR=pwd
cd ${SRCDIR}  ----> at this point ,I will move to /opt/HORCM,so my pwd has to be /opt/HORCM.

if [${SRCDIR}==${WRKDIR} ];  ,, here i Need to check if i am currently in /opt/HORCM
echo "i am in ${SRCDIR}"

./horcmuninstall.sh   ->horcm manager unintsall
else
echo " i am in some other file"
exit 0
fi

 

but if i use as WRKDIR=$(pwd),it takes the current  workingpath

 

so my condition is not met .

 

is my understanding correct ?

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>6  if [${SRCDIR}==${WRKDIR}];

 

This should be:

    if [ ${SRCDIR} = ${WRKDIR} ]; then

 

>how can I export the current working dir?

 

Since you are using a real shell, you can simply do:

   WRKDIR=$PWD

 

>WRKDIR=${pwd}
>Do both syntax are correct?

 

The syntax is correct but the semantics are different.  The later gets the value of $pwd, which is only available in the scummy C shell.  It is better to use the shell variable $PWD.

 

>but if I use as WRKDIR=$(pwd), it takes the current  workingpath

 

The CWD of when you did the command, before you did the cd ${SRCDIR}.

tempsample
Frequent Advisor

Re: automation installation of package

Hi,

 

I got it.

 

 

but now i got trouble in to other point.

 

ls -l /opt | grep H????
dr-xr-xr-x   8 root       sys           8192 Jul  3 17:43 HORCM
drwxr-xr-x   3 root       sys             96 Jun 21  2012 HORCM_20120622
drwxr-xr-x   3 root       sys             96 Jul  2 20:30 HORCM_20130702
drwxr-xr-x   2 root       sys             96 Jul  3 17:51 HORCM_20130703

 

i need to delete the dir HORCM.

 

ls -l /opt | grep -c HORCM

4  --> since there are four HORCM named,i am getting the output as 4.

 

but I have to grep only HORCM.

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>ls -l /opt | grep H????

>I need to delete the dir HORCM.

 

Any reason you don't just delete it?

  rm -rf /opt/HORCM

 

You could also be pedantic and check first:  if [ -d /opt/HORCM ]; then

 

>ls -l /opt | grep -c HORCM

>4  --> since there are four HORCM named ,I am getting the output as 4.

>but I have to grep only HORCM.

 

If you only want to check for /opt/HORCM you can do the above "test -d".

Or you can list that specific directory:

ls -ld /opt/HORCM

 

You also anchor your above grep:

ls -l /opt | grep -c " HORCM$"

 

Which makes sure there is a leading space from the ll(1) output and nothing after the "...CM".

tempsample
Frequent Advisor

Re: automation installation of package

Hi Dennis

 

 

ls -l /opt | grep -c " HORCM$"

 

above cmd worked for me.

 

 

i have completed the raid manager upgrade script.

 

 

All are working fine.

 

 

but after this I need to run pairdisplay for all DG.

 

 

how can I grep only DG from horcm conf file.

 

after grep,i need to run

 

something like  may be i should grep the DG list and move it a file

 

 

export DEVICE GROUP= all DG list

 

pairdisplay -g $DEVICEGROUP -fcx  -CLI -IBC0

 

 

Dennis Handly
Acclaimed Contributor

Re: automation installation of package

>how can I grep only DG from horcm conf file?
>DEVICEGROUP= all DG list

 

What is the format of this file?  Do you expect multiple DGs?

Do you need to invoke pairdisplay once for each DG or once with the list of all of them?