Catching the termination of one script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Catching the termination of one script
# 1  
Old 09-17-2009
Catching the termination of one script

Hi
I have a Shell script that needs to execute a command at the
End of the excursion of other script And I cant get a handel
On the trap command. And that is if the trap command
Is the proper way to go

this is a extract of the script

Code:
MYHOST=`hostname| cut -d. -f1`
echo $MYHOST

   cd /var/powerpassword/v3.4/ppsparc_solarisV-3.4.15-1/install
exec  ./ppinstall -b $MYMASTER  $MYHOST ;
#
########################################################
# Trap the successfull completion of ppinstal
########################################################
trap ppinstall 0
ppinstall()
{
  echo "Caught Signal ... ."
  ppadmin trace > /var/tmp/`hostname`-trace-result.txt
  echo "Done  ... quitting."
  exit 1
}


Last edited by Franklin52; 09-21-2009 at 11:45 AM.. Reason: Please use code tags!
# 2  
Old 09-17-2009
The 'exec' command means 'replace the shell with the command I give here'. After you run 'exec ./ppinstall' your shell no longer exists and can't trap anything. Smilie Remove the exec and you won't need trap at all, since the shell script will continue running after ppinstall completes.

Last edited by Corona688; 09-17-2009 at 02:05 PM..
# 3  
Old 09-17-2009
Yes thank you

IJust dicovered that also. Now I have a nwe issue whit the same script

A loop that has issue :-(

Code:
MYVER=`uname -a | awk '{print $3}'`
   echo  $MYVER
{
   if  ["$MYVER" = "5.10"]
then
      /usr/sbin/svcadm disable telnet
else 
  /usr/sbin/ppadmin stop
}


Last edited by Franklin52; 09-21-2009 at 11:45 AM.. Reason: Please use code tags!
# 4  
Old 09-17-2009
Please put code in code tags. [ code ] stuff [ /code ] without the extra spaces in the tags.

Code:
MYVER=`uname -a | awk '{print $3}'`
   echo  $MYVER
{
   if  ["$MYVER" = "5.10"]
then
      /usr/sbin/svcadm disable telnet
else 
  /usr/sbin/ppadmin stop
}

What are the { } brackets for? This doesn't look like a function. Did you want to do something like this?
Code:
MYVER=`uname -a | awk '{print $3}'`
   echo  $MYVER

if  ["$MYVER" = "5.10"]
then
      /usr/sbin/svcadm disable telnet
else 
      /usr/sbin/ppadmin stop
fi

# 5  
Old 09-21-2009
Hi All

I have resolved all my issues whit this
Script. Thank you all for you inputs

I’m posting the finished script fell free to criticize
And if it can be improved please tell me

Code:
#!/bin/sh
# Script to uninstall & install ppugrade
#
######################################################################
# Some variables
MYMASTER=server1
MYMASTSLAVE=server2
SUBJECT="Your rmote job is completed on `hostname`"
TO=user@company.com
SPOOLFILE=/var/tmp/`hostname| cut -d. -f1`-trace-result.txt
#####################################################################

## Move some files
    cd /etc/
    cp pam.conf pam.conf-preupgrade;
    echo Copying pam.conf pam.conf-preupgrade
    cp /etc/pam/ORIG /etc/pam.conf
    echo Copying /etc/pam/ORIG /etc/pam.conf
    mv /var/adm/ppserv.log  /var/ppserv.log-preupgrade #Getting a clean install log
#
#
## Check if we are Solaris 10

MYVER=`uname -a | awk '{print $3}'`
   if [ "$MYVER" = "5.10" ]
   then
   echo Execution de svcadm:  `/usr/sbin/svcadm disable powerpasswordt`
   else
             ppadmin stop
   fi
#
######################################################################
# Begin uninstall of PowerPassword
######################################################################
#
   cd /var/pp-old

   echo "\n\n Would you like to unistall powerpasswor on `hostname` (y/n)?"
    read YN
    #
    case $YN in
    [yY]*) echo Y |  ./ppuninstall
            ;;
    [nN]*) echo "Terminating gracefully TTFN .\n"
                exit 0
            ;;
    esac
#
##########################################################
# Begin install of PowerPassword
##########################################################
#

MYHOST=`hostname| cut -d. -f1`
    echo $MYHOST
    cd /var/powerpassword/v3.4/ppsparc_solarisV-3.4.15-1/install
   ./ppinstall -b $MYMASTER  $MYHOST ;
#
#   Move back some files
    cp /var/pp.orig/passwd /var/pp/passwd
    cp /var/pp.orig/pwhistory /var/pp/pwhistory
    cp /var/pp.orig/passwd.key  /var/pp/passwd.key
    cp /etc/pam.conf-preupgrade  /etc/pam.conf
#
########################################################
# Trap the successfull completion of ppinstal
########################################################
#
trap ppinstall 0

ppinstall()
  echo "Caught Signal ... ."
  ppadmin trace > /var/tmp/`hostname | cut -d. -f1`-trace-result.txt;
  echo "ppadmin trace is done check mail."
  echo "Sending the E-mail message..."
  /usr/bin/mailx -s "${SUBJECT}" ${TO} < $SPOOLFILE


Last edited by Franklin52; 09-21-2009 at 11:47 AM.. Reason: Please use code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Email alert after termination

I am running the gaussian program on UNIX with bash and I want to form a script that will email me once the output life terminates either "normal termination" or "false" I just started learning this last week so could you let me know how to go about this.:b: (13 Replies)
Discussion started by: Jade_Michael
13 Replies

2. Shell Programming and Scripting

Script termination without pressing Enter key[nohup]

I have a script in which we have used nohup. Once script is executed it will be terminated only when enter key is pressed. I want the script to be terminated without pressing enter key nohup imqbrokerd -name user_id port 2>1 1>$home_`date` & I am a newbie to shell, Kindly please help (3 Replies)
Discussion started by: Suganbabu
3 Replies

3. AIX

A question about scsi termination

http://ep.yimg.com/ay/iercomputer/ibm-39j5022-ultra320-scsi-adapter-dual-channel-pci-x-fc5736-3.gif I have bought this controller. Simple and fast question: I will put on this controller a external LTO tape,which is terminated with a terminator. I have to put another terminator on PCI-controller... (1 Reply)
Discussion started by: Linusolaradm1
1 Replies

4. Shell Programming and Scripting

Cat termination in script

So, I'm writing a shell script to help automate a process I'm doing. Basically I want to take input from the user for 2 variables, then create a file that consists of: Variable1,Variable2 Constant1 Constant2 .. Constant2000 then run an awk script. I'm pretty new to unix though, and so... (11 Replies)
Discussion started by: Parrakarry
11 Replies

5. Shell Programming and Scripting

Problem with ssh termination...

hi all, i have a situation where i run ssh command from a unix machine to execute few scripts on 2 other unix machines. my problem is, the scripts that i run will start few commands on the 2 servers and will quit....i am able to quit from the script but i have to give ctrl+c (on the... (10 Replies)
Discussion started by: niteesh_!7
10 Replies

6. Shell Programming and Scripting

Bash: Catching the returncode from a script and using within another script?

Hello, I want to run a bash script in another bash script, depending on the returncode or exitcode. But I don't know how to handover the returncode to the second bash script!? I tried this dummy script which should return the exit code 1 #test.sh echo "test" exit 1 But... (3 Replies)
Discussion started by: ABE2202
3 Replies

7. Shell Programming and Scripting

random script termination

I'm writing a script to archive data. First, the files are all rsync'd to the archive directory via NFS mounts(I know not the most efficient, but the only choice in this situation), then I use md5sum to validate the transfers. During execution of the script, it will exit for no apparent reason. It... (6 Replies)
Discussion started by: mph
6 Replies

8. UNIX for Advanced & Expert Users

Child peocess termination.

Hello all, Here is the problem: A ksh script (let's call it abc.sh) gets kicked off from a menu program using "nohup abc.sh &". The process ID of abc.sh can be recieved (pid=$!). abc.sh runs an Oracle PL/SQL script (it creates a child process). In order to stop the abc.sh (and the child)... (5 Replies)
Discussion started by: Shaz
5 Replies

9. UNIX for Dummies Questions & Answers

Abnormal Termination errors

I'm having trouble with Abnormal Termination errors. What are they, what causes them and how can I prevent them from happening? Are they application specific? (2 Replies)
Discussion started by: bialsibub
2 Replies
Login or Register to Ask a Question