While killing the process, Script gets hanged. Please help me on this.

Hi Everyone,

I have written a script to automate the docbase cleanup process on every weekly basis. That is in this script i have to shutdown the docbase and then kill all the process that are hanged except one process(epic process) and need to delete some log files and then i have to start the docbase.

The following is the content of the script,

#!/bin/ksh
# docbase cleanup process
DM_DBA=/apps/documentum/dba
cd $DM_DBA

# Next, set up the logfile.
logdir=/apps/documentum/dba/log
if [ ! -d $logdir ] ; then
echo "$0: Fatal error: missing directory $logdir"
exit 1
fi

logfile=/apps/documentum/dba/log/test.log
echo "\n *Space before cleanup process \n" > $logfile
df -k >> $logfile

# process running before shut down
echo "\n *************** Process running before shutdown **************** \n" >> $logfile
ps -ef|grep doc >> $logfile

#shut down Legal
echo "\n ************** shut down Legal ************** \n" >> $logfile
./dm_shutdown_legal >> $logfile
status=$?
if [ ! $status = 0 ] ; then
cat <<-END
***** ERROR DURING LEGAL SHUTDOWN *****
The legal dmshutdown utility reported a non-zero status **
END
exit 1
fi

#shut down Docbroker
echo "\n ********** shut down Docbroker **************\n" >> $logfile
./dm_stop_docbroker
status=$?
if [ ! $status = 0 ] ; then
cat <<-END
***** ERROR DURING DOCBROKER SHUTDOWN *

The docbroker shutdown utility reported a non-zero status *

END
exit 1
fi

#Killing all the process except the Epic process
echo "\n *** Killing process except epic process ******* \n" >> $logfile

ps -ef|grep doc| grep -v '/apps/documentum/epic5.1/bin/sun4r5/adeptlmd -s180 -e /apps/documentum/epic5.1/'|grep -v grep|awk '{print $2}'| xargs kill -9
echo "after killing the process"

#Delete test.out file in buildcd
buildcddir=/apps/documentum/cdrom/apps/buildcd
if [ ! -d $buildcddir ] ; then
echo "\n $0: Fatal error: missing directory $buildcddir \n" >> $logfile
exit 1
fi
buildcdfile= $buildcddir/test.out
if [ -f $buildcdfile ]
then
echo "\n *************** test.out file exist in builcd path ****************\n" >> $logfile
rm $buildcdfile >> $logfile
fi

#starting docbroker
echo " \n ************* starting docbroker ************** \n" >>$logfile
./dm_launch_docbroker >>$logfile
status=$?
if [ ! $status = 0 ] ; then
cat <<-END
***** ERROR DURING DOCBROKER STARTUP *****
The docbroker start utility reported a non-zero status **
END
exit 1
fi

#starting legal
echo "\n ************** starting legal *********** \n" >> $logfile
./dm_start_legal >>$logfile
status=$?
if [ ! $status = 0 ] ; then
cat <<-END
***** ERROR DURING LEGAL STARTUP *****
The legal start utility reported a non-zero status **
END
exit 1
fi

In the above code, the script gets hanged while executing the statement ps -ef|grep doc| grep -v '/apps/documentum/epic5.1/bin/sun4r5/adeptlmd -s180 -e /apps/documentum/epic5.1/'|grep -v grep|awk '{print $2}'| xargs kill -9

After this statement, the script is not executing any statement.

If i remove this line alone, the script is running without any problem.
But i have to kill all the processes that are hanged after the docbase has been shutdown. and then i have to start the docbase by calling another script which has been already written.

Can anyone please tell me why is my script get hanged at this statement.

Kindly please help me on how to resolve this probelm.

Thanks in advance.

Regards,
Sheethal

escape the "/" with \

i.e..

use \/apps\/documentaion etc....

Hi,

But if i execute this command ps -ef|grep doc| grep -v '/apps/documentum/epic5.1/bin/sun4r5/adeptlmd -s180 -e /apps/documentum/epic5.1/'|grep -v grep|awk '{print $2}'| xargs kill -9
individually i dont have any issues, only when i execute this command in the script it gets hanged that is after this statemnt no other statement is getting exectued.

can u please tell me why does it behaves like this........

It seems the problem is with "xargs kill -9", the trailing end of the script. Better avoid using it and do as follows:

 kill -9 `ps -ef|grep doc| grep -v '...'|grep -v grep|awk '{print $2}'` 

or else use "for" loop to get each process id and then do kill -9.

or else you can use this also, if you know the process name before hand

ps -ef  | awk '$0~/<process-name>/&&$0!~/awk/{print $2}' | xargs kill -9

BTW, "kill -9" is a really awful thing to do, it doesn't give a process the opportunity to clear up, and "atexit()" callbacks don't run.

This can then leak semaphores, shared memory, leave AF_UNIX sockets lying around and generally be really unkind.

Hi royalibrahim,

I tried your both solutions,

kill -9 `ps -ef|grep doc| grep -v '...'|grep -v grep|awk '{print $2}'`

and

ps -ef | awk '$0~/<process-name>/&&$0!~/awk/{print $2}' | xargs kill -9

But still the script is getting hanged, any statement after this statement is not executed even a echo statement is not getting exectued.

As you had said i believe the problem is while killing the process because when i give only the command
ps -ef|grep doc| grep -v '...'|grep -v grep|awk '{print $2}'

the script is getting executed without any problems.

But when i append the command kill -9 along with ps -ef | awk '$0~/<process-name>/&&$0!~/awk/{print $2}' then the script is getting hanged that is no statement is executed after this kill statement.

I dont have any clues about this issue and i am very new to Unix. kindly please help me on this.

Thanks in advance.

Have you tried the "for" loop? for eg:

for pid in `ps -ef | grep doc |  grep -v '...' | grep -v grep | awk '{print $2}'` 
do
    echo $pid
    # kill -9 $pid
done

here replace '...' after the grep -v with your complete search string '/apps/doc...' and try to print the relevant process IDs. See whether u are able to print it. Then go with "kill" statement (that is why I commented it here). And also ensure the process ids to be killed should not belong to any daemons.

N.B: And also in the earlier command try altering the xargs kill -9 to xargs -i kill -9 {} 2> /dev/null and run it

Hi,

I have tried using for loop also but still the issue exist for eg,

for pid in `ps -ef|grep doc| grep -v '/apps/documentum/epic5.1/bin/sun4r5/adeptlmd -s180 -e /apps/documentum/epic5.1/'|grep -v grep|awk -F" " '{print $2}'`
do
echo $pid
if [ $pid ]
then
echo "inside if"
kill -9 $pid

status=$?
if [ ! $status = 0 ] ; then
echo "error while killing the process"
fi

echo "after killing"
fi
done

In the above code, the script is running up to the statement echo "inside if"
After this statement, it prints "killed" and after that no other statement is getting executed.

I also have checked whether the script is running after it had printed "killed" by using the command ps -ef but i couldnt able to see any process running related to this script.

I am not killing any Daemons process because once the docbase has been shutdown, mostly all the process will be killed. I am writing this script to kill the process which are hanged even after the docbase has been shutdown. so i believe most probably there will not be any chance of killing Daemon process.

I dont know what is wrong in my code, please help me on this issue.

Hi,

Now it is working, i have changed the code to

for pid in `ps -ef|grep doc| grep -v '...........'|grep -v grep|awk -F" " '{print $2}'`
do
echo $pid
if [ $pid ]
then
echo "inside if"
kill -9 ${pid} 2> /dev/null
echo "after killing"
fi
done

Thanks for all your help