Convert duration of the process to seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert duration of the process to seconds
# 1  
Old 10-24-2011
Convert duration of the process to seconds

Hi,

I am looking to write a script to kill the process which are running for more than 7 days.
So i have a command like
"ps -eo pid,etime,args | grep -i xxxx" ( process which has xxx in it and running for more than 7 days needs to be killed ).
When i exeucte the above command , i am getting the ouptut as
4340 2-01:43:00 /bin/ksh /sdfas/sfasd/xxxx/
6178 3-01:41:08 /bin/ksh /sfsf/asfs/xxxx
7573 4-03:25:14 /bin/ksh /sfsf/dfgdfg/xxxx

second fields will tell me the duration of time. How can i convert this duraction to seconds instead of format "days-hour:min:sec".
If i can convert everything to second, i will use awk command like "$2 > seconds " and kill the process.

How can i convert the time to seconds...
Your response is appreciated.
Thanks in Advance.
# 2  
Old 10-24-2011
Code:
$ echo "7573 4-03:25:14 /bin/ksh /sfsf/dfgdfg/xxxx" |
        awk '{ split($2, A, ":"); split(A[1], B, "-"); $2=A[3] + (A[2]*60) + (B[2]*3600)+(B[1]*3600*24) } 1'
7573 357914 /bin/ksh /sfsf/dfgdfg/xxxx
$

# 3  
Old 10-24-2011
Why do you need convert to second, you can use the exist day number to kill directly

Code:
ps -eo pid,etime,args | grep -i xxxx|awk '$2~/-/{split($2,a,/-/);if (a[1]>=7) print $1}' |xargs kill

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Mp3 duration rounded up to nearest seconds

Hi, can anyone provide more details to why an audio file's duration is seen as 10 seconds on unix and 9 seconds on windows Read about windows MFT rounding down to nearest seconds, is there any article on unix rounding up? thanks in advance (1 Reply)
Discussion started by: wsps1750
1 Replies

2. UNIX for Beginners Questions & Answers

Process duration

Hi , How can I check that for a single process, for example pagent for how much duration this process was up or down and also I need multiple entries if this process was down or up multiple times. Please help. (3 Replies)
Discussion started by: Ashish Garg
3 Replies

3. Shell Programming and Scripting

Convert a future date into epoch seconds on HPUX system

Hi All, I have scenario where i have to compare two dates. I thought of converting them to epoch seconds and do a numeric comparison. This works fine on Linux systems. $ date -d '2015/12/31' +%s 1451538000 $ date +%s 1449159121 But we don't have -d option in HPUX. What would be... (5 Replies)
Discussion started by: veeresh_15
5 Replies

4. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

5. Shell Programming and Scripting

Compare fraction number and convert duration to seconds

Hi friends, I have a file with contents below: 01.m4a 00:14:45.82, 01.mp4 00:03:46.05, -659.770000 05.m4a 00:27:43.51, 05.mp4 00:27:45.10, 1.590000 06.m4a 00:11:39.73, 06.mp4 00:11:44.60, 4.870000 If 5th column value more than 3 or less than -3 then I should get its name (from first... (2 Replies)
Discussion started by: magnus29
2 Replies

6. Shell Programming and Scripting

Convert Date from File and Calculate Duration

Hi - I am looking for a little help to read in 2 date fields from a file in format: 20120508134012.3 yyyymmddhhmmss.tenths of a second So i want to: 1. Read in the 1st date from the file 2. Read in the second date from the file 3. Calculate the difference in minutes (or seconds) 4. ... (5 Replies)
Discussion started by: Newbie2012
5 Replies

7. Shell Programming and Scripting

Script to add time convert to seconds

Hi, What i am looking for and i am new to this too, is a bash script that will add time in the format hh:mm:ss and produce the answer in minutes or seconds. It needs to be a loop since there are hundreds of times in my file. This is data is from a CDR that calculates duration of time used. ... (2 Replies)
Discussion started by: trotella
2 Replies

8. Shell Programming and Scripting

How to delay the process for few seconds

Hi, In my shell script, (as per the requirement), I am creating few files, and the processes are launched parallelly . (by using "&" at the end of the command line). As per the logic, I need to remove these files as well, after creating. But, the problem is, due to parallel processing,... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

9. Shell Programming and Scripting

Convert Seconds to hh:mm:ss

Hi All I need to convert a number of fields in a record from seconds to hh:mm:ss ( or possibly hhh:mm:ss ). I'm guessing awk is the way to go . File has multiple records and each record contains 101 fields - can awk handle that ? The seconds values will be in fields 3 - 101 and could be 0. ... (4 Replies)
Discussion started by: Mudshark
4 Replies

10. Shell Programming and Scripting

awk convert seconds to time of day

Does anyone know of a way to convert "seconds" to time of day in "hh:mm:ss" ? Trying to do in awk with strftime but with no luck. Thanks (2 Replies)
Discussion started by: timj123
2 Replies
Login or Register to Ask a Question