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:
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?
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)
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)
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)
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)
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)
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)