Operating System - HP-UX
1833873 Members
2149 Online
110063 Solutions
New Discussion

How to trap exit signal by swlist or swinstall command

 
Sutapa Dey
Frequent Advisor

How to trap exit signal by swlist or swinstall command

Hi All,

I need a little help. I have written a shell script which validates whether a particular software is present in a given number of depot files. Now whenever I execute the swlist command in the shell script, and if it finds that the software is not present in the software depot, it exits the script without executing the loop in the script. Please find the script as below :

#!/usr/bin/sh -e

set -x
set -v

BUNDLE="/home/sutapa/doclist"
LOGFILE="/home/sutapa/logfile"
DEPOT="/var/depot/VSM"

if [ ! -f $BUNDLE ]
then
echo "No bundles to install:create the bundle file" ; exit 0 ;
fi

if [ -f $LOGFILE ]
then
rm -rf $LOGFILE
fi

while read line
do
for VAR in $DEPOT/*.depot
do
swlist -s $VAR $line
a=`echo $?`
if [ $a -eq 0 ]
then
swinstall -s $VAR $line
echo "BUNDLE:$line" >> $LOGFILE
echo "DEPOT:$VAR" >> $LOGFILE
fi
done
done < $BUNDLE

Please let me know.
3 REPLIES 3
Binu George
Advisor

Re: How to trap exit signal by swlist or swinstall command


This behaviour is a result of the '-e' flag given to the shell.

From 'man ksh',
------------------------------------------------
-e If the shell is non-interactive and if a
command fails, execute the ERR trap, if set,
and exit immediately. This mode is disabled
while reading profiles.
------------------------------------------------

Removing this flag should continue the execution of the script, even when swlist fails.
Sutapa Dey
Frequent Advisor

Re: How to trap exit signal by swlist or swinstall command

Thanks a lot it is working now.
Dennis Handly
Acclaimed Contributor

Re: How to trap exit signal by swlist or swinstall command

a=`echo $?`

The proper way to do this is just: a=$?

If you don't need the value except right after, you can use:
if [ $? -eq 0 ]; then