script to kill a pid giving error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to kill a pid giving error
# 1  
Old 07-08-2012
Bug script to kill a pid giving error

Hi,

I simply want to kill a running process using a script that read pid from a file and tries to kill it .Getting error as shown below code..

Code:
cat $HOME/BackupScript.ksh.run | head -1 | while read pid
do
ps -p $pid > /dev/null 2>&1
if [$?=0]; then
kill -9 $pid
else
echo "no running $pid to kill" > /dev/null 2>&1
fi
done

Code:
kill_backup.ksh[12]: [1=0]:  not found.

Please suggest me how do I eliminate this error ..

Last edited by methyl; 07-10-2012 at 03:04 PM.. Reason: sort out tags
# 2  
Old 07-08-2012
Code:
if [ $? -eq 0 ]; then

# 3  
Old 07-09-2012
Or you could use double equals signs (==).

Here is a useful if reference for Bash, should be good for other shells too.
Introduction to if
# 4  
Old 07-10-2012
Network Still same error message

Please assist..
# 5  
Old 07-10-2012
"Still same error message" isn't in any way helpful feedback.

What OS are you using? What shell? Post (using code tags) exactly how you modified the script, how you ran it, and the exact error message generated. What's the output of cat $HOME/BackupScript.ksh.run | head -1?

Also, your echo command is pointless. You've redirected stdout to /dev/null and then stderr to the same destination as stdout. It will never echo anything. Perhaps you meant to redirect echo's output to stderr? If so, drop all those redirections and simply use 1>&2.

Regards,
Alister
# 6  
Old 07-10-2012
Quote:
kill_backup.ksh[12]: [1=0]: not found.
Error is on line 12 (numbered from zero). There are not 13 lines in your script.
Please post the current version of the script and the current error message.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

2. Shell Programming and Scripting

Unix Script -- Suggestions to list and kill PID's sequentially

Hi, I'm trying to write a script where i'm trying to grep the PID and the associated file and list them. Then execute the KILL command sequentially on the listed PID's for ".tra" files ==================================================== ps -aux | grep mine adm 27739 0.2 0.8 1131588... (12 Replies)
Discussion started by: murali1687
12 Replies

3. Shell Programming and Scripting

Kill a PID using script

Hi, I wrote a script to kill a process id. I am able to kill the PID only if I enter the root password in the middle of the execution because I did not run as root i.e after i run the script from the terminal, instead of killing directly, it is killing only after entering the pass when it... (12 Replies)
Discussion started by: rajkumarme_1
12 Replies

4. Shell Programming and Scripting

Help with script to stop a user giving kill command on a server!!

Hi, I am new to shell scripting and want to create a script with the follwoing description: I want to restrict the users from giving a kill command on a unix server. The server have a restricted logins with login id and passwords. I want a script that will find out if a user has given a... (9 Replies)
Discussion started by: shell_scripting
9 Replies

5. Shell Programming and Scripting

Kill a Script based on the pid and sleep

I would want to run a code for 1 min and if it doesnt succeed in 1 min..I would want to exit it..I am using the following code...But the script is not going into my code part.It is waiting for 60 secs and then getting killed. The code which is in the while loop actually takes less than 60 secs...... (6 Replies)
Discussion started by: infernalhell
6 Replies

6. Shell Programming and Scripting

grab PID of a process and kill it in a script

#!/bin/sh who echo "\r" echo Enter the terminal ID of the user in use: echo "\r" read TERM_ID echo "\r" ps -t $TERM_ID | grep sh echo "\r" echo Enter the process number to end: echo "\r" read PID echo "\r" kill -9 $PID What this code does is ultimately grab the PID of a users sh... (6 Replies)
Discussion started by: psytropic
6 Replies

7. Shell Programming and Scripting

getting Ambiguous error on kill -9 @pid from csh

Hello all i have simple script that executing program every 10 seconds im invoke this script as daemon with second script that put it in the background this is my first script (IsAliveTester.csh) #!/bin/csh -f @ iSleep = 10 set processName = "ClientTester" while(1) $processName ... (0 Replies)
Discussion started by: umen
0 Replies

8. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

9. Shell Programming and Scripting

pass pid to kill using script

Hi there, i wonder if anyone can help is there any way that i can write a script that will kill all current ftp processes, for example if ps -ef | grep ftp produces 3 active proceses, then I would like to somehow extract the PID for each one and pass that to kill -9 has anybody done this... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

10. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question