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.

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

For the root permission you should check out "sudo".
Check this:

For activation cron is a good suggestion to execute the script with some interval; for more info check this:

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.

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:

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. :cool:

HTH,

Regards,

Praveen

@zaxxon:
Sudo is not installed on our HP-UX server, but I'll talk to our administrator later today.

@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

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.

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:

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, :cool:

Regards,

Praveen

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.