Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/bin/sh
DATE1=`date +"%y""%m""%d""%H""%M"`
tmpfile=/tmp/KILL$DATE1.log
sqlplus system/manager<<EOF
set linesize 500
set pagesize 1000
set heading off
set feedback off
spool $tmpfile
select
'ALTER system kill session '''|| s.sid || ',' || s.serial# ||''';' Kill,'kill -9 '||p.spid "KILL OS PID"
from v\$session s,v\$process p where s.paddr=p.addr and s.status='INACTIVE'
spool off
EOF
which produces two columns of values like this :
ALTER system kill session '1663,6809'; kill -9 12018
ALTER system kill session '1731,7947'; kill -9 14073
ALTER system kill session '1921,52004'; kill -9 6066
Now, I want to take the first statement ALTER system kill session '1663,6809'; in sqlplus and run all the commands and after running th e same in oracle, I want to kill all the OS associated OS process using the 2nd column kill 09 12018 . how can I acheive this ?.. is there anyway I can modify the above script to take the output and kill the sessions at the database level and OS level?
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731
Rep:
Hi,
you can run both commands from within sqlplus.
You have to set a ! in front of the OS command.
This looks like:
ALTER system kill session '1663,6809'; !kill -9 12018
Both can be executed by changing your script this way, that it will execute $tempfile at the end.
This should look like this:
-------------begin---------------------------------------
#!/bin/sh
DATE1=`date +"%y""%m""%d""%H""%M"`
tmpfile=/tmp/KILL$DATE1.log
sqlplus system/manager<<EOF
set linesize 500
set pagesize 1000
set heading off
set feedback off
spool $tmpfile
select
'ALTER system kill session '''|| s.sid || ',' || s.serial# ||''';' Kill,'!kill -9 '||p.spid "KILL OS PID"
from v\$session s,v\$process p where s.paddr=p.addr and s.status='INACTIVE'
spool off
@$tmpfile
EOF
--------------------end--------------
SQL> ALTER system kill session '1764,60569'; ! kill -9 12151
2 /
ALTER system kill session '1764,60569'; ! kill -9 12151
*
ERROR at line 1:
ORA-00911: invalid character
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.