473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need a script(.ksh) to kill oracle process automatically

I want a unix script to kill oracle processes automatically for example who logged more than 20 hours.
Sep 21 '13 #1
7 2513
Nepomuk
3,112 Expert 2GB
Well, you can build one. Here are a few things that might help:
  • The following code will display the PIDs and elapsed running times of all processes found called <name>:
    Expand|Select|Wrap|Line Numbers
    1. ps $(pgrep <name>) -o pid=,etime=
    Leaving out the "pid=" option will give you only the time.
  • You can kill a process with the PID <pid> with the command
    Expand|Select|Wrap|Line Numbers
    1. kill <pid>
  • The test command allows you to compare values and react to the results.
That should be enough to get you started. :-)
Sep 21 '13 #2
this we need to do manually but i need it automatically without manual intervention daily.
Sep 21 '13 #3
Nepomuk
3,112 Expert 2GB
That shouldn't be a problem. Here's what I'd do:
  1. Write a script that can do the job manually as described above
  2. Use cron to automate the job, which means crating a crontab entry that might look something like this:
    Expand|Select|Wrap|Line Numbers
    1. # Run this job once per day at 1:15 am
    2. 15 1 * * * /opt/scripts/killOldOracleJobs.sh
Cron is very useful so learning about crontabs is a good idea anyway.
Sep 21 '13 #4
but the process id (pid) need to give manually here,if we have twenty users whose log on time more than 20hours all those all users need to kill.

need to happen automatically based on the time period.
Sep 21 '13 #5
Nepomuk
3,112 Expert 2GB
That's what the ps-command in my first reply is for. If you know the name of the processes (e.g. "oracle"), you can find all instances of that process including the time it's been running. So, you can make a list, filter it by the times the processes have been running and then kill the various processes in a for-loop.
Sep 21 '13 #6
numberwhun
3,509 Expert Mod 2GB
Just adding my .02 to this thread.

You can easily modify the ps command to grab the pid by using awk. Here is an example, that you can take and modify accordingly, that will grab the pid for the current sshd process and print it out:

Expand|Select|Wrap|Line Numbers
  1. ps | grep /usr/sbin/sshd | grep -v grep | awk '{ print $2 }'
  2.  
Sep 25 '13 #7
Nepomuk
3,112 Expert 2GB
Or, using the syntax in my first reply, you could use
Expand|Select|Wrap|Line Numbers
  1. ps $(pgrep /usr/sbin/sshd) -o pid=
and get the same result without needing awk or pipes. :-P
Sep 25 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Wilfried Mestdagh | last post by:
Hi, I use C# 2005 beta with NET 2005 beta. How to kill a process ? Is this possible in this version ? I foundsom things in help but it is not clear to me, if someone can give me brief example it...
2
by: charmis | last post by:
Hi everyone, I am trying to include one feature using excel object in my application. I am giving the code to create and kill the process , that i got from Microsoft site.......but nothing is...
1
by: Lee Gillie | last post by:
I need to be able to kill a process programmatically under ASP.NET. IIS runs under the local system account. The user accessing the web is using anonymous access. We would prefer NOT to grant...
2
by: touf | last post by:
Hi, I use the folowing code to create a new Excel file using a query It creates an excel file and save it on the disc, but When I double-clic on it (explorer) it open Excel and bloc,(don't display...
7
by: Joe | last post by:
If I'm using process.kill, I can only kill processes, which are created in the same login session. (I'm using win2000, I'm in the local admin group) Processes created by me in earlier logins or...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
3
by: elrondrules | last post by:
Hi Am new to python and need your help!! this is my code snip. within my python script I have the following commands.. <snip> import os
4
by: yxq | last post by:
Hello, I want to kill the Explorer process, after Explorer process has been killed, it will restart automatically immediately. How to disable it restart automatically? for example, in Windows Task...
6
by: Archanak | last post by:
Hi, I want to kill a process at 5.00 p.m . I tried using crontab. In crontab i gave like this:- 17 00 * * * kill processid.(say 1234)
1
by: sindhujanan | last post by:
hai, anyone plz tell the code to connect oracle using database
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.