crontab or looping script to Kill process from user


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers crontab or looping script to Kill process from user
# 1  
Old 02-10-2009
crontab or looping script to Kill process from user

I am looking for a way to kill 2 processes from a user through some kind of script.

Using an oracle script, I get two process ids that need to be killed.

Code:
SQL> select ssn.process as client_process_id, pcs.spid as oracle_process_id, ssn.sid, ssn.serial#
  2  from v$session ssn inner join v$process pcs on (pcs.addr = ssn.paddr) where ssn.module = 'MARC_RFD248';

CLIENT_PR ORACLE_PR        SID    SERIAL#
--------- ---------  ----------  ----------
18690     18692             37        738

I can create a file with the lines:

kill -9 <oracle_process_id>
kill -9 <client_process_id>

and make it executable, but the username for the file isn't the one with the rights on the process ids.

Is there a way to get this file to be picked up by a script run as root and executed?

The file should be run as soon as it is fully created (like within one minute or so). What would be a better option, run through crontab, or by using a loop / lockfile?

It should be possible to create more than one of these files, so the filename should be variable.

Thanks in advance
# 2  
Old 02-10-2009
For the root permission you should check out "sudo".
Check this:
https://www.unix.com/shell-programmin...read-file.html

For activation cron is a good suggestion to execute the script with some interval; for more info check this:
https://www.unix.com/answers-frequent...n-crontab.html

If you can get the output displaying the PIDs in a row like "1122 45559 29392", you can just issue 1 kill with them all as parameter. Also better issue a normal kill without -9. And after a sleep of let's say 10 seconds, you can issue the kill with -9, just to make sure the processes are able to end and clean up everything they had allocated.
# 3  
Old 02-10-2009
Meert,

All Oracle process ids are owned by the oracle software owner (like oracle).

Sounds like you do not have access to oracle user, yet you want to kill processes owned by that user, which can only be done a super user like root.

Usually, killing the session in oracle should clean the unix processes too.

As sys, run the below:

Code:
SQL> alter system kill session 'sid,serial#';

If there is some limitation which prevents you from running the above, then we can think of something. Smilie

HTH,

Regards,

Praveen
# 4  
Old 02-10-2009
Quote:
Originally Posted by zaxxon
For the root permission you should check out "sudo".
@zaxxon:
Sudo is not installed on our HP-UX server, but I'll talk to our administrator later today.

Quote:
Originally Posted by sunpraveen
Meert,
All Oracle process ids are owned by the oracle software owner (like oracle).

Sounds like you do not have access to oracle user, yet you want to kill processes owned by that user, which can only be done a super user like root.

Usually, killing the session in oracle should clean the unix processes too.

As sys, run the below:

Code:
SQL> alter system kill session 'sid,serial#';

If there is some limitation which prevents you from running the above, then we can think of something. Smilie

HTH,

Regards,

Praveen
@Praveen:

The issue is that the alter system command leaves the original proccesses running in UNIX.

The case at hand is that it is an RF handscanner that connects through telnet to the database. If the scanner loses connection, we can do a reset of the database connection through alter system but for the user to reconnect to the scanner, we need to kill only the rfprocess ids and leave the display process running.

I hope this makes sense
# 5  
Old 02-10-2009
Note that the below script is an infinite loop. So, you have to either do Ctrl+C or kill the process id to end it.

Code:
while true
do
login=username/password@connect_string
sqlplus -s "$login" << EOF > /tmp/process_id_to_kill.txt
@find_process_ids_to_kill.sql
EOF
kill `cat /tmp/process_id_to_kill.txt`
sleep 20
kill -9 `cat /tmp/process_id_to_kill.txt`
sleep 60
done

contents of find_process_ids_to_kill.sql:

Code:
set head off
set feed off
set verify off
select ssn.process as client_process_id, pcs.spid as oracle_process_id
from v$session ssn inner join v$process pcs on (pcs.addr = ssn.paddr)
where ssn.module = 'MARC_RFD248';

Note that the above script would work only if it is the owner of the process that it is killing. If not, then it cannot kill. Then you would have to use root or any other superuser.

HTH, Smilie

Regards,

Praveen
# 6  
Old 02-10-2009
Praveen, thank you very much. This is a good start and I'll try and work from here.

I tried to spool the output to the process_id_to_kill.txt from an sql script but got a "cannot spool" access denied message, probably because the file was in use by the "infinite loop" script.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris, grant user to kill another process

the task is grant user1 to kill another (for example user2) process. My steps: by root: usermod -P "Process Management" user1 login user1 user1@server (~) pfexec kill <PID> the result is: ksh: <PID>: not found or user1@server (~) pfexec pkill <PID> the result: nothing happens, still... (0 Replies)
Discussion started by: dsyberia
0 Replies

2. Shell Programming and Scripting

Kill all process of Oracle user

Hi folks, I want to kill all process of oracle user and won't kill shell, should i try this? Please confirm. 1st way pgrep -u oracle | sudo xargs kill -9 2nd way killall -u oracle (2 Replies)
Discussion started by: learnbash
2 Replies

3. UNIX for Dummies Questions & Answers

Kill Duplicated Process by shell in crontab

Hi! I need your help, please. I'm in AIX node and sometimes listener process from an oracle instance gets duplicated, i mean that it get spawned a second listener process. As we can't apply changes to the databases on this months, i want to build a shell that can identify the second... (6 Replies)
Discussion started by: Pactows
6 Replies

4. UNIX for Advanced & Expert Users

kill process owned by another user

How can I kill a process owned by user1? I will be using another user (user2) (not root) and we are on the same primary and secondary group. I copied everything including it's .profile and set the path accordingly. user1@hostnmae0:/home/user1 $ pkill java pkill: Failed to signal pid 1234:... (2 Replies)
Discussion started by: lhareigh890
2 Replies

5. Shell Programming and Scripting

Kill Process not owned by other user

Hi Here is my problem: 1)I am login to unix server through my login id and do SU - xxx 2) Start the script which is running in background I want that other user which login to there id and do SU - yyy(Different user) kill that script. Could you please help me in this. (9 Replies)
Discussion started by: mr_harish80
9 Replies

6. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

7. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

8. UNIX for Dummies Questions & Answers

how to kill all the netscape process of a particular user?

how to kill all the "netsacpe" processes of a particular user? (1 Reply)
Discussion started by: karthi_g
1 Replies

9. Shell Programming and Scripting

how to kill a process initiated by other user at the same group

Hey I'm writing a script that creates some processes,and some scripts which kill those processes. the question is Simply: How can I allow a group members to be able to kill (using kill command) processes created by other user at the same group? and i need the change to be at the script... (5 Replies)
Discussion started by: The Dark Knight
5 Replies

10. Shell Programming and Scripting

kill a process initiated by crontab

Hi, I scheduled one script through crontab command and seems like it is hanging. I come to know this through the command 'ps -ef' whcih is showing me the program running, but no chances of it to take more than 2hrs to comlpete. I want to kill that process. I tried to kill it using the... (6 Replies)
Discussion started by: DILEEP410
6 Replies
Login or Register to Ask a Question