Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in a small script !! please help

Status
Not open for further replies.

poolboy

MIS
Jan 25, 2002
44
GB
thgis script is suppose to kill all java processes using their pids. please find below as I found it

#
# Any errors or messages are sent to a ddmmyy.log logfile, where
# yymmdd represents the date on which the log is created.

Configuration: You should not change any of the environment variables. If the NT HOME
# variable is set other than the directory where these scripts are, then
# you should change the SCRIPTDIR variable to reflect the full path.
# e.g. SCRIPTDIR=//d/Was_Admin/Overnight
#
# Due to a limitation in the cygwin's kill command, it cannot be used here.
# The current implementation uses the NT Resource Kit's Kill.exe command.
# Unlike Unix kill, NT's kill takes one pid at a time. Thus this script
# loops round in a for loop attempting to kill each pid in turn. When
# you migrate over to Unix, you should uncomment the line:
#
# "#$SCRIPTDIR/kill.exe -9 $PIDS >> $LOGFILE 2>&1"
#
# and remove the for loop.
#

export TODAY_DATE=`date +%y%m%d`
export KILLDIR=//c/WINNT/system32
export SCRIPTDIR=//d/Was_Admin/Overnight
export LOGFILE=${SCRIPTDIR}/logs/${TODAY_DATE}.log

#date >> $LOGFILE
echo `date +%D:%T` " - Checking for stale applications ....." >> $LOGFILE

export PIDS="`ps -W | grep java | awk '{ print $1 }'`"

if [ "$PIDS" != "" ]
then
#echo "" >> $LOGFILE
echo `date +%D:%T` " - Attempting to kill stale applications with pids \"$PIDS\" ....." >> $LOGFILE
# ${SCRIPTDIR}/kill.exe -9 $PIDS >> $LOGFILE 2>&1

for pid in $PIDS
do
${KILLDIR}/Kill.exe $pid >> $LOGFILE 2>&1
done
fi

#echo "" >> $LOGFILE
#date >> $LOGFILE
echo `date +%D:%T` " - Cleared all applications." >> $LOGFILE
echo "" >> $LOGFILE
 
Maybe your problem would be solved by reading the comments in the code:

# When you migrate over to Unix, you should uncomment the line:
#
# "#$SCRIPTDIR/kill.exe -9 $PIDS >> $LOGFILE 2>&1"
#
# and remove the for loop.

 
A much easier way of doing this would be

kill `ps -ef|grep java|grep -v grep|grep -v ksh|awk '{print $2}'`

the grep -v excludes certain processes from being killed, you could also use kill -9, or any other flag

Mike --
| Mike Nixon
| Unix Admin
| ----------------------------
 
thanks mrn,
do you think my code is okay and should work ?

regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top