Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nelly22

macrumors 6502
Original poster
Sep 29, 2009
366
5
I have few rows of my own code i would like to run when this script kills distnoted.

It propably needs if ... end if type or thing.

How i can do this?

ps -reo '%cpu,uid,pid,command' |
awk -v UID=$UID '
/distnoted agent$/ && $1 > 100.0 && $2 == UID {
system("kill -9 " $3)
}
'
 
Hi,

I'm not entirely sure what you're trying to do there. However, "if" in UNIX works like this:

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

...so an example might be:

Code:
if [ 1 -eq 1 ]; then

  #do something

fi

Hi an Thanks.

I try to do some thing like this:
Code:
IF ps -reo '%cpu,uid,pid,command' | awk -v UID=$UID ' /distnoted agent$/ && $1 > 100.0 && $2 == UID
    kill distnoted (system("kill -9 " $3))
    my code1 here
    my code2 here
END IF

So basically i want to add couple of my own rows of code after kill row and my rows are run only if kill row was run.
 
Last edited:
Code:
command1 && command2

command2 only runs if command1 is successful

Thanks.

I don't know what to do with this code.

It would be much simpler and readable for newbie if all are in own rows.

Actually this would be better:
Code:
IF ps says its over 100
    kill
    IF kill was succesfull
        my code 1
        my code 2
    else
        my code 1
        my code 2
    END IF
END IF
 
You can do stuff like this:
Code:
if ps -reo '%cpu,uid,pid,command' | awk -v UID=$UID ' /distnoted agent$/ && $1 > 100.0 && $2 == UID;then
    kill distnoted (system("kill -9 " $3))
else
    echo "Command failed"
fi
[doublepost=1469814804][/doublepost]If you look up 'bash programming' online you can find many guides to help you :)
 
You can do stuff like this:
Code:
if ps -reo '%cpu,uid,pid,command' | awk -v UID=$UID ' /distnoted agent$/ && $1 > 100.0 && $2 == UID;then
    kill distnoted (system("kill -9 " $3))
else
    echo "Command failed"
fi
[doublepost=1469814804][/doublepost]If you look up 'bash programming' online you can find many guides to help you :)

Thanks.

I think i have now problem with $3. What ever that is.

I tried this, because if i turn this unix script to AppleScript, then i can easily combine unix and AppleScript rows and integrate it better with my other scripts:

Code:
if (do shell script "ps -reo '%cpu,uid,pid,command' | awk -v UID=$UID ' /distnoted agent$/ && $1") > 100 then
  do shell script "kill distnoted (system("kill -9 " $3))"
  my AppleScript code here
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.