Beginner bash script

Hi folks :slight_smile: This is my first post, nice to meet y’all.
I’d really like some constructive criticism (hope I’m posting in the right place).

#! /bin/bash
for var in "$@"
line=$(ps -fC $var | grep root)
if [ -z "$line" ]
	killall -9 $var
exit 0

Is the logic ok? Any potential problems?

it’s rubbish if it’s supposed to show all logged on users…

Sorry, my roundabout way of saying “it might help if you stated what the script is supposed to do” :wink:

:slight_smile: thanks.
Iterate over parameters, check if process is owned by root, if not kill it.


pgrep -v -u root

identify all non root owned processes by PID ?

as the “-v” option makes it the “inverse” of:

pgrep -u root

then just pipe the returned PID list to “killall -9” … just a thought.

or maybe I’m over-thinking it :-\

Mmm, I think all you need is;

#! /bin/bash
for var in "$@"
  pkill -v -u root ${var}

But I’ll let you test it on your system … . :o

You guys are very funny!
That kills all processes except the one specified as the argument!