Finally got it working.. added following filters for user procs older 5 days in this case.
I would have coded the check for greater than 5 days differently. At least with the version of awk I've got installed in various places, your code doesn't work. Here is the output using your ps command from one of my boxes:
When I pipe that through your awk ($5 > "5") the output is this:
which as far as I can tell is wrong. It should have listed all of the processes that are shown as being 12 days old in addition to the one that it did list.
The problem is that you are doing string comparison, instead of doing numeric comparison and a string which begins with a '1' is less than a string that begins with a '5'.
I make a habit of always 'casting' fields to force them to be numeric before doing any kind of numeric comparison with them. I've been bitten countless times by forgetting this. To fix the problem, change your awk:
Notice that there are no quotes round the 5, and that +0 causes the fifth field to be converted to integer before doing the comparison. A string like 12-20:31:50 becomes an integer 12 when 0 is added to it, and the comparison yields the expected result. With the changes:
You should also notice the change to the grep that avoids picking up a record for a process active less than 24 hours (it matched the dash in the cpu column, and the change forces it to match a dash only between two numbers as would appear in the date column.) You can also eliminate the grep completely:
Last edited by agama; 02-08-2012 at 07:49 PM..
Reason: clarification, addition of elimination of grep
I will like to write a script that delete all files that are older than 7 days in a directory and it's subdirectories. Can any one help me out witht the magic command or script?
Thanks in advance,
Odogboly98:confused: (3 Replies)
Hi all,
I want to delete log files with extension .log which are older than 30
days. How to delete those files?
Operating system -- Sun solaris 10
Your input is highly appreciated.
Thanks in advance.
Regards,
Williams (2 Replies)
Hi, I need a .ksh script that lists all the process that are currently running and older than 3 days. once the process list is available i need to mail the list and then kill those processes.
Quick response is highly appreciated :b:
Thanks in Advance!!!
Sri (3 Replies)
Dear all,
i use incremental backup my data with .zip to my hard drive. what i need is i don't want the old .zip file older than 30 days. how to write a shell script automatically remove my external hard disc zip backup folders older than 30 days?
Regards, (2 Replies)
Hi All,
I am trying to automate some stuff to make my 'to-do-things' easier. I am in need for help regarding this.
I have an output
root 17187 3465 0 23:00:00 ? 0:01 Process1
root 4975 4974 0 May 12 ? 0:00 Process2
root 4042 16713 0 Jan 30 pts/22 0:00... (4 Replies)
Hi All,
OS :- HP-UX wm5qa B.11.23 U ia64 1119805695 unlimited-user license
I need to search files older than 50 days. I've used following command in order to search desired files, I also discoverd, it's showing today's files as well. Do you have any clue with this ?
wmqa1> find .... (4 Replies)
Hi All,
I am new to the scripting and using solaris 10 OS. Please suggest me from the below script which modifications need to be done to delete the files more that 2days older. Current script is deleting existing file.
# Remove old explorer runs if needed
DIR=`dirname ${EXP_TARGET}`
if ... (2 Replies)
Hi,
Could someone help me that what the problem is in this code?
#!/bin/sh
FOLDER=/abc/datasource/checkstatus
TIMESTAMP=$(date +%s)
for filename in $(find $FOLDER -maxdepth 1 -type f -name "CHECK_STATUS*"); do
f1=$($filename -Eo "{4}+")
f2=$(date -d "$f1" +%s)
if... (11 Replies)