How-to verify if my package installed successfully


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How-to verify if my package installed successfully
# 1  
Old 12-09-2016
Hammer & Screwdriver How-to verify if my package installed successfully

Can you please let me know how can i verify /check inside the script if the below to package installation commands are successful or if they failed for any reasons?

1. pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg
2. pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log

Code:
uname -a
SunOS mymac 5.11 11.2 sun4v sparc sun4v

# 2  
Old 12-09-2016
You do it with pkgadd the same way you do it with every other command... You check the man page for the utility in question to see what exit code it produces when it succeeds. You run the command. You check the exit code after the command completes. And, if the exit code matches the exit code listed on the man page for that utility for successful completion, then you know the command succeeded; otherwise, it failed.

As with about 99.44% of utilities, pkgadd exits with exit code 0 if it completed successfully. Of course, the way you check the exit status varies depending on the shell you use (and you haven't bothered to tell us what shell you use). If we make the wild assumption that you're using sh, ksh, bash, or /usr/xpg4/bin/sh (or another shell based on Bourne shell syntax), you could try something like:
Code:
pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log
ec=$?
if [ $ec -eq 0 ]
then	echo 'pkgadd succeeded'
else	echo "pkgadd failed as indicated by diagnostics above and exited with exit code $ec"
fi
exit $ec

# 3  
Old 12-09-2016
Wouldn't pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log
always succeed even if pkgadd fails becoz of the redirection >/tmp/install.log being successful ?
# 4  
Old 12-09-2016
Quote:
Originally Posted by mohtashims
Wouldn't pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log
always succeed even if pkgadd fails becoz of the redirection >/tmp/install.log being successful ?
If this would be the case UNIX would be VERY wrong - and, in fact, it isn't. You probably confuse that with a pipe (cmd1 | cmd2 | cmd3) where you get only one exit code for all the commands.

@Don:

Quote:
As with about 99.44% of utilities,
Its 99.43978210653% +/- one epsilon - roundabout. ;-))

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 12-09-2016
Quote:
Originally Posted by mohtashims
Wouldn't pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log
always succeed even if pkgadd fails becoz of the redirection >/tmp/install.log being successful ?
Good question. No, because a redirection is not a separate command. In the case of a simple command it is considered part of the simple command..

Quote:
A "simple command" is a sequence of optional variable assignments and redirections, in any sequence, optionally followed by words and redirections, terminated by a control operator.
Shell Command Language: Simple Commands

So the return code reflects whether the simple command as a whole succeeded or not...

Quote:
If a command fails during word expansion or redirection, its exit status shall be greater than zero.
Shell Command Language: Exit Status for Commands

Last edited by Scrutinizer; 12-12-2016 at 11:57 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 12-12-2016
Hammer & Screwdriver

So, #!/bin/bash -e will exit the script even if pkgadd fails in the below statement ?
Code:
pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log

# 7  
Old 12-12-2016
Quote:
Originally Posted by mohtashims
So, #!/bin/bash -e will exit the script even if pkgadd fails in the below statement ?
Code:
pkgadd -a $INSTP/install/dadmin -d $INSTP/install/apachesrv.pkg>/tmp/install.log

Yes.

And, you know that you can easily test this out with the script:
Code:
#!/bin/bash -e
echo before
false > junk
echo after

which if you save this in a file, make it executable, and run it will print before, create an empty file named junk, and exit without printing after.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Problem when trying to remove a package using rpm command - error: package is not installed

Hello, i have installed a package by using the command sudo rpm -i filepackage.rpm package filepackage is already installed when i try to remove it, i get an error saying "is not installed": sudo rpm -e filepackage.rpm error: package filepackage is not installed How can... (4 Replies)
Discussion started by: g_p
4 Replies

2. Red Hat

How to verify the current NIC driver version installed in RHEL5.3??

Guys, Can you help me how to verify the current installed NIC driver version in RHEL5.3? Thanks.:D (1 Reply)
Discussion started by: shtobias
1 Replies

3. Solaris

Package needs to be installed for using pam_mkhomedir.so?

Hi, What is the necessary package that needs to be installed for using pam_mkhomedir.so in pam.conf file? And from where can i get that file? Is that package already shipped with Solaris 10? Because when i use that file i am getting "open_module: stat(/usr/lib/security/pam_mkhomedir.so)... (1 Reply)
Discussion started by: sathya47
1 Replies

4. Ubuntu

Download same package as installed

Hi gurus, how to (just) download already installed package ? I tried sudo apt-get -d install putty but gives me Reading package lists... Done Building dependency tree Reading state information... Done putty is already the newest version. 0 upgraded, 0 newly installed, 0 to... (7 Replies)
Discussion started by: wakatana
7 Replies

5. HP-UX

how to package my program which can be installed on HP UX

I develop a unix program in HPUX I want to package my program to install on HPUX in some dierctory folder like /user/local/sbin/xxx and preinstall some software before install my program package like xxx.depot how can i do it, have any tools like use setupfactory tools in windows ... (4 Replies)
Discussion started by: alert0919
4 Replies

6. Shell Programming and Scripting

how to verify sqlplus not installed on solaris

i want to write shell script that exit by displaying error if sqlplus is not installed. The platform is oracle10g on solaris sparc. I tried the which sqlplus command, but it returns errorcode 0 even sqlplus is not installed. Kindly help? (3 Replies)
Discussion started by: mmunir
3 Replies

7. UNIX for Dummies Questions & Answers

How do I verify the integrity of a package? And how do I configure yum to add a site

How do I verify the integrity of a package? And how do I configure yum to add a site (3 Replies)
Discussion started by: 3junior
3 Replies

8. HP-UX

Verify Hardware installed HP-UX11

Hi - Basic question from newbie I need to find out how to verify hardware installed on HPUX server. Mid-range server - as in i need to prove to customer that a specific cpu is installed, so much memory is installed, etc. PLEASE HELP. TA (16 Replies)
Discussion started by: hoffies
16 Replies

9. UNIX for Dummies Questions & Answers

Verify Hardware installed on HP-UX 11

Hi - Basic question from newbie I need to find out how to verify hardware installed on HPUX server. Mid-range server - as in i need to prove to customer that a specific cpu is installed, so much memory is installed, etc. PLEASE HELP. TA (1 Reply)
Discussion started by: hoffies
1 Replies

10. UNIX for Dummies Questions & Answers

Successfully Installed Solaris 8 after all.

Hello There, Aftar all i successfully installed Solaris 8 on my Primary Slave 2nd Hard disk. Here what i did. I kept my first hard disk (Windows Me) on primary Master and put my new 2nd hard disk on Primary Slave, CDROM is on Secondary slave. When i install solaris8 it ask me two... (0 Replies)
Discussion started by: abidmalik
0 Replies
Login or Register to Ask a Question