Shell script to find out process name that are running for last 10 days.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to find out process name that are running for last 10 days.
# 1  
Old 04-06-2016
Shell script to find out process name that are running for last 10 days.

Hi all,

As i am new to shell script.Please help me to write a Shell script to find out process name that are running for last 10 days.

Thank's in advance.
# 2  
Old 04-06-2016
Hi Manas,

It is generally not possible to identify which processes have run in the past, I say generally because some processes will write log files etc. So if this information is known, you may be able to retrospectively identify processes that have ran in the past.

I would suggest that you start with the ps utility, information can be found in the man pages.

You don't mention OS, platform or any other information which may allow us to assist you.

Regards

Gull04

Last edited by gull04; 04-06-2016 at 06:45 AM.. Reason: Code Tag Change
# 3  
Old 04-06-2016
OS is Red hat Enterprises linux 5.
# 4  
Old 04-06-2016
Hi Manas,

Some guidance on the way that processes work which may possibly help you.

To check the current process list, you can use a command like ps (process status) an example would be ps -ef showing the active list of processes.

The information presented provides much information about the process, even the ps command will show in this list. It will only exist "while the command is running", it will have a unique PID (Process ID) each time it is run. Once the process has completed there is no evidence that it has ever been there, to capture the data that you have requested - you would have had to start 10 days ago.

Regards

Dave Munro
# 5  
Old 04-06-2016
It is not quite clear what you really want. Should it be "processes running that started more than ten days ago", ps with a keyword or format specifier could help:
Quote:
KEYWORDS
The following is a complete list of the available keywords and their
meanings. Several of them have aliases (keywords which are synonyms).

.
.
.
etime - elapsed running time, format [days-][hours:]minutes:seconds.
# 6  
Old 04-06-2016
Can i write the script like the following code to get the process name.
please suggest any other way if you can.

Code:
#!/bin/sh

for var in `ps -ef` 

# getting the TIME field of the ps -ef command

running_day =`echo $var | awk -F " " ' { print $7} ' | cut -d ':' -f1`

# comparing the running_day with given time
if [ running_day -ge 10]
then
# taking the process name

process_name=`echo $var | awk -F " " ' { print $8} ' | cut -d ':' -f1`
fi
echo $process_name

Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 04-06-2016 at 12:25 PM.. Reason: Added code tags.
# 7  
Old 04-06-2016
Are you aware that in plain (linux!) ps -ef field 7 is the TIME field, i.e. accumulated cpu time, which has no relation to the process' start time at all?

WHAT EXACTLY are you after?

Your script is missung the for loop's do and done, and why don't you extract "running_day" and "process_name" in one go?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cancel process running for more than 5 days

Hello Group, We want to create a script in order to filter process in the system with more than five days (STIME) and then kill them under Solaris 10. How can we filter these kind of process ? ps -efa Thanks in advance for your help (4 Replies)
Discussion started by: csierra
4 Replies

2. Shell Programming and Scripting

Shell Script to find out if a process is running on any all machines

Hi All, I have been a guest visitor from a long time and this forum is wonderful. I finally am a member of this forum too, so i am here stuck with a shell script that i was trying to write My requirement is that i should be able to create a shell script which will check if a process is running on... (3 Replies)
Discussion started by: Rex0226
3 Replies

3. Shell Programming and Scripting

shell script to find a process by name and kill it

hi, Am a newbie to unix and wasnt able to write script to my requirement. I need a shell script, which should find a process by name and kill it. For eg: let the process name be "abc". I have different processes running by this name(abc), so should kill them all. Condition would be: if... (7 Replies)
Discussion started by: fop4658
7 Replies

4. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

5. Shell Programming and Scripting

How to find out list of all proccess which are running on unix servers from last two days.

Hi All, I have a requirment, i need to get the list of all the process which are running from last two days on my unix server and also to put this list into an another file. i am giving you a sample example : $ ps -ef UID PID PPID C STIME TTY TIME CMD (1 Reply)
Discussion started by: akshu.agni
1 Replies

6. Shell Programming and Scripting

Cron job running for some days and is not running for some days

Hi.. i have written a shell script and made this script to run on every day night 11: 55 pm using a cron job. This cron job running for some days and is not running for some day. but i need this script to run every day night. Please help me. Here is the cron tab entries, 55 23 * * *... (1 Reply)
Discussion started by: vidhyaS
1 Replies

7. Shell Programming and Scripting

Shell Script, Copy process using find.

Ok, so here is what I am looking for.. Shell script that uses find to look for one days worth of data using the modified date and then copies only those files to a specified directory. I figured I could use grep and the find command to do this. It seems to work just fine from what I can... (4 Replies)
Discussion started by: techjunky
4 Replies

8. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

9. UNIX for Advanced & Expert Users

how to check if a process is running in a server from shell script.

I want to write a unix shell script that will check if a process (say debu) is running in the server or not. If no , then send a mail to the corresponding person to start the process??? (2 Replies)
Discussion started by: debu
2 Replies

10. Programming

to find current running process

Hi All, The scenario is like this: There is a process say "A" which create a child process say "B" if some condition is true and process "A" terminates. "B" invokes some C program say "C" using 'execl' function. The job of program "C" is to keep polling the server until the server will be up.... (2 Replies)
Discussion started by: ranjkuma692
2 Replies
Login or Register to Ask a Question