Ksh script function, how to "EXIT 2" without killing the current process?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ksh script function, how to "EXIT 2" without killing the current process?
# 1  
Old 10-08-2009
Ksh script function, how to "EXIT 2" without killing the current process?

Hi,

Using AIX 5.3 and Ksh.
Code:
 
/>ls -al /usr/bin/ksh
-r-xr-xr-x 5 bin bin 237420 Apr 10 2007 /usr/bin/ksh
/>

I recently started working for a new employer. I have written UNIX K-Shell scripts for many years and have never had this particular issue before. Its perplexing me.

I have the following script:
Code:
#
# KillBadMonitorDaemons.sh
#
# Searches for duplicate processes and echoes findings
#
 
function  killbadmonitordaemons {
echo "Searching for rogue Monitor Daemon processes...\n"
for mysite in `cat /qdxtest/qdx5.4/integrator/prodsites`
do
 
  # echo and setsite to check
  echo "Checking site: $mysite"
  #setsite $mysite   #; purposely commented to make it fail and hit "exit" command.
 
  # Verify the setsite command was successful
  sitecheck=`showroot | grep "HCI site" | awk '{print $4}'`
  if [[ $sitecheck != $mysite ]]
  then
    echo "Setsite Command was unsuccessfull. Aborting Script.\n"
    exit 2
  fi
 
  #echo "Getting pid from hcisitectl command"
  goodpid_sitectl=`hcisitectl | grep hcimonitord | awk '{print $6}'`
 
  #echo "Getting pid from file HciSiteDir/exec/hcilockmgr/pid"
  goodpid_pidfile=`cat $HCISITEDIR/exec/hcimonitord/pid`
  #echo "Making sure the two pids match. If not, don't do anything for this site."
  if [[ $goodpid_sitectl != $goodpid_pidfile ]]
  then
 
     echo "** pid file and hcisitectl do not match for $mysite.\nSkipping $mysite.\n"
 
  else
    #echo "Good Monitor Daemon for site $mysite is running on pid: $goodpid_sitectl"
    #echo "Grepping for bad Monitor Daemon pids for site $mysite"
    for mypid in `ps -ef | grep "$mysite " | grep hcimonitord | grep -v $goodpid_sitectl | awk '{print $2}'`
    do
 
      #echo `showroot`
       echo "$mysite: Found rogue Monitor Daemon running on pid $mypid"
       echo "`ps -ef |grep "$mysite " | grep hcimonitord`\n"
       #kill -9 $mypid
       sleep 3
 
    done
 
  fi
 
done
echo "\n*** Done searching ***"
}
# execute main function
killbadmonitordaemons
unset mysite goodpid_pidfile goodpid_sitectl mypid sitecheck

When I execute this script from the command line list this:
Code:
 
/>pwd
/qdxtest/qdx5.4/integrator/troytest
/>KillBadMonitorDaemons.sh

the EXIT command ends my current Telnet session.

So, I added a line at the top:
Code:
 
#!/usr/bin/ksh

It still ends my Telnet session even though (I thought) #!/usr/bin/ksh should be telling the script to execute in a new shell process. RIGHT?

So, I tried changing the line at the bottom which calls my function to fork a new proces.
Code:
 
echo `killbadmonitordaemons`

Then when I run my script again...
Code:
 
/>pwd
/qdxtest/qdx5.4/integrator/troytest
/>KillBadMonitorDaemons.sh
Searching for rogue Monitor Daemon processes... Checking site: tds Setsite Command was unsuccessfull. Aborting Script.
ksh[59]: KillBadMonitorDaemons.sh:  not found
/>

PATH Environment Variable:
Code:
/>echo $PATH
/qdxtest/qdx5.4/integrator/troytest/bin:
/qdxtest/qdx5.4/integrator/troytest/scripts:
/qdxtest/qdx5.4/integrator/bin:
/qdxtest/qdx5.4/integrator/contrib:
/qdxtest/qdx5.4/integrator/sbin:
/qdxtest/qdx5.4/integrator/dbms/bin:
/qdxtest/qdx5.4/integrator/tcl/bin:
/qdxtest/qdx5.4/integrator/clgui/bin:
/qdxtest/qdx5.4/integrator/clgui/java/bin:
/qdxtest/qdx5.4/integrator/usercmds:
/usr/bin:/etc:/usr/sbin:/usr/ucb:
/home/hci/bin:/usr/bin/X11:/sbin:
.:
/usr/local/bin:/usr/local/scripts:
/opt/pware/samba/3.0.23d/bin

Directory listing where script resides:
Code:
/>pwd
/qdxtest/qdx5.4/integrator/kshlib
/>ls -al *.sh
-rwxrwxr--   1 hci      staff          1202 Oct  8 12:54 KillBadLockManagers.sh
-rwxrwxr--   1 hci      staff          1619 Oct  8 13:58 KillBadMonitorDaemons.sh
-rwxrwxr--   1 hci      staff          1263 Sep 24 16:08 monitorDbStates.sh
-rwxrwxr--   1 hci      staff          1479 Oct  2 15:27 showThreadQueues.sh
/>

I appears my script directory isn't even in the PATH and yet I can execute the script from anywhere. I don't get it. My co-workers say it has always been this way.

Anyway, it appears that running the script like this is causing my "\n" to stop working. And, what is the "not found" message? Am I doing something wrong?

I've never had problems creating scripts which execute in a new shell and have the EXIT command work as expected without strange results.

Possibly, our shell is different or some OS setting is different than previous environments I've worked in?

Thanks for any assistance.
# 2  
Old 10-08-2009
I think you may have a script by the same name somewhere in your path.
I suggest you do a find on your paths...
# 3  
Old 10-08-2009
I renamed the script and there doesn't appear to be any other script by this name in my path.

Code:
/>KillBadMonitorDaemons.sh
Searching for rogue Monitor Daemon processes... Checking site: tds Setsite Command was unsuccessfull. Aborting Script.
ksh[59]: KillBadMonitorDaemons.sh:  not found
/>
/>pwd
/qdxtest/qdx5.4/integrator/kshlib
/>ls -al *.sh
-rwxrwxr--   1 hci      staff          1523 Oct  8 15:14 KillBadLockManagers.sh
-rwxrwxr--   1 hci      staff          1624 Oct  8 15:19 KillBadMonitorDaemons.sh
-rwxrwxr--   1 hci      staff          1263 Sep 24 16:08 monitorDbStates.sh
-rwxrwxr--   1 hci      staff          1479 Oct  2 15:27 showThreadQueues.sh
/>mv KillBadMonitorDaemons.sh tmm_KillBadMonitorDaemons.sh
/>KillBadMonitorDaemons.sh
ksh: KillBadMonitorDaemons.sh:  not found
/>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Problems with "exit" called from function in bourne script

Hi everyone. #!/sbin/sh EXITING() { umount /FOLDER rm -Rf /FOLDER echo "EXIT" exit 0 } EXITING echo "OK" (8 Replies)
Discussion started by: vacadepollo
8 Replies

3. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

4. UNIX for Dummies Questions & Answers

How can I show my "current" directory as the KSH prompt?

Hi All, This is an embarrassingly simple question and couldn't think of "keywords" to search for the answer, but how do I change my UNIX/KSH prompt to show the machine name and my "current" but not "full" directory? For example: if the machine name is "machine" and I'm currently in... (4 Replies)
Discussion started by: chatguy
4 Replies

5. Red Hat

"service" , "process" and " daemon" ?

Friends , Anybody plz tell me what is the basic difference between "service" , "process" and " daemon" ? Waiting for kind reply .. .. (1 Reply)
Discussion started by: shipon_97
1 Replies

6. HP-UX

script running with "ksh" dumping core but not with "sh"

Hi, I have small script written in korn shell. When it is called from different script, its dumping core, but no core dump when we run it standalone. And its not dumping core if we run the script using "/bin/sh" instead of "ksh" Can some body please help me how to resolve this issue. ... (9 Replies)
Discussion started by: simhe02
9 Replies

7. Shell Programming and Scripting

Shell script process remains after "exit 1"

I have a script that performs an oracle export: <snip> if then exp / full=y file=${exp_file} log=${exp_log} direct=y feedback=1000000 STATISTICS=NONE buffer=20000000 else exp / full=n owner=${schema_name} file=${exp_file} log=${exp_log} direct=y feedback=1000000... (4 Replies)
Discussion started by: Squeakygoose
4 Replies

8. HP-UX

ERROR: more than one instance of overloaded function "vprintf" has "C" linkage

Hi people! I've got this own library: -------------------------------------------- Personal.h -------------------------------------------- #ifdef __cplusplus extern "C" { #endif #include <stdio.h> #include <stdarg.h> #include <string.h> ... (0 Replies)
Discussion started by: donatoll
0 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. Programming

How to convert the "select" function into a "poll" function

i have a program using the select function but i want to convert it to poll... how can i do this? thanks in advance... :) (1 Reply)
Discussion started by: rbolante
1 Replies
Login or Register to Ask a Question