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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script file in ksh not working 1

Status
Not open for further replies.

bensheares1

IS-IT--Management
Sep 12, 2003
6
0
0
SG
Hi All,

Here's a script to kill all Clients with processes named "Client"

However, sometimes it worked and sometime it doesnt.
And I do not know what's wrong.

This is written by someone in Korn shell. Does this able to work using other shells, eg. csh and sh?
If not, how to make it work in csh or sh? What changes do I have to make?

>kill_client
no response

%kill_client
no response

========================================================
Filename:kill_client
#/usr/bin/ksh

ps | /usr/bin/grep Client | /usr/bin/grep -v grep | awk ' { KILL_CMD = sprintf("kill -9 %d",$1); system(KILL_CMD); print("KILL CLIENT " $1); } END { } '
========================================================

Anyone know whats wrong with it please let me know.

Thanks.

Best Regards,
Bensheares
 
I have used this script on Solaris and AIX extensively and have tested it once on HP. Syntax for the command would be:

killit.sh Client


Script:

# This line gets the process number for the value passed in the
# command (java, for WebSphere) and writes the PID only to
# a text file. the grep -i ignores case on the command line.

PID=`ps -e | grep -i $1 | awk '{ print $1 }' > /home/utility/bin/pid.txt`

# This line cats the file created in the line above and says while
# catting the file, read each line.

cat /home/utility/bin/pid.txt | while read LINE

# This line tells the system to do a kill -9 on each PID that is
# listed in the pid.txt file.

do kill -9 $LINE
# This line closes up the do line.
done


 
Don't forget to add the #!/usr/bin/ksh at the beginning of the script and to set the PATH so the script finds ps, cat, do, kill, etc. Or add the whole path to the commands in the script.
 
First off, it's not a Korn shell script. For it to execute in Korn shell, you need to make the first line -

#!/usr/bin/ksh (note the '!')

As it is, it just executes in whatever shell that you're currently running. The code seems pretty simple so it should run fine regardless.

Second, when you say "no response" do you mean that it hangs or just returns with no output?

If it's hanging, I'd check for an extra " " (space) after one of the line continuation slashes '\'. They need to be the last thing on the line.

Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top