Jump to content

Recommended Posts

Posted

Hi,

Hoping someone can help me. I am new in using linux and trying to create a bash shell script to take a process name from the user and if the process isn't owned by root then it should be killed.

 

I can get the kill process part working (see below) but don't know how i should get the code to check if process is owned by root.

 

#!/bin/bash
echo -n 'Please enter process name: '
read process
ps -ef | grep $process | awk '{print $2}' | xargs kill -9

 

any help would be appreciated.

 

cheers,

 

H

Posted
Hi,

Hoping someone can help me. I am new in using linux and trying to create a bash shell script to take a process name from the user and if the process isn't owned by root then it should be killed.

 

I can get the kill process part working (see below) but don't know how i should get the code to check if process is owned by root.

 

#!/bin/bash
echo -n 'Please enter process name: '
read process
ps -ef | grep $process | awk '{print $2}' | xargs kill -9

 

any help would be appreciated.

 

cheers,

 

H

 

 

Not sure exactly what you are trying to achieve with this but...

 

ps -NU root

 

will give you a list of processes which are not owned by root, you can grep as you wish then.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...