Operating System - HP-UX
1820213 Members
3699 Online
109620 Solutions
New Discussion юеВ

Scripting question from a beginner

 
SOLVED
Go to solution
Matt Szary
Advisor

Scripting question from a beginner

I am trying to kill users pids inside of a script. I need to be root in order to do this. I am using the su - root -c , but it is asking for a password. I do not want to have to enter a password as I need this script to run without operator intervention. Any suggestions will be appreciated.
9 REPLIES 9
Scott D. Allen
Regular Advisor

Re: Scripting question from a beginner

Kim,

That's pretty dangerous, as the script will allow you to automatically kill pids without authentication....assuming anyone can run the script.

However, if you must do this, try using sudo and making sure you have assigned the correct priviledges and permissions. ie. make sure that the script is only executable by those who need to use it and they have the appropriate permissions in sudoers.

HTH.

--Scott
"Sometimes the devil you know is better than the devil you don't know."
Scott D. Allen
Regular Advisor

Re: Scripting question from a beginner

Kim,

That's pretty dangerous, as the script will allow you to automatically kill pids without authentication....assuming anyone can run the script.

However, if you must do this, try using sudo and making sure you have assigned the correct priviledges and permissions. ie. make sure that the script is only executable by those who need to use it and they have the appropriate permissions in sudoers.

HTH.

--Scott
"Sometimes the devil you know is better than the devil you don't know."
Antoanetta Naghiu
Esteemed Contributor
Solution

Re: Scripting question from a beginner

Start the script as root. They were discution in this forum about providing the password via script.
You can use sudo for a specific user.
Do a search in forum for sudo. You'll get the web site where to download it from, instruction how to configurew it.
As a remark, for using the kill command for your own processes you do not need to be root. I mean user1, can kill the processes under user1 ownership. But user1 need root (or sudo) to kill the processes that belongs with user2.
Rick Garland
Honored Contributor

Re: Scripting question from a beginner

That is dangerous! The root account should be used exclusively for this purpose. I would be leary of having a user become root to do this. sudo would be a great tool for doing this but I would restrict who has the sudo rights to become the root user. If you put sudo on and anybody can become root, then anyone can do the kills.
Victor BERRIDGE
Honored Contributor

Re: Scripting question from a beginner

I agree with Scott, the only safe way I know to do this is to use sudo, go at the
Software Porting And Archive Centre For HP-UX

And download a copy

Good luck
Victor
Rick Garland
Honored Contributor

Re: Scripting question from a beginner

If this must be done, here is a command line that can be used:

ps -ef | grep 'x' | awk '{ system( "kill " $2) }'

The 'x' is the placeholder for whatever you would want to grep for.
CHRIS_ANORUO
Honored Contributor

Re: Scripting question from a beginner

Check the attached script and also this, make a file, you must be root to do this:
ee=`ps -e|grep (user process)|grep "?"|cut -c2-6`
kill -9 $ee
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Fred Martin_1
Valued Contributor

Re: Scripting question from a beginner

I worked at a place that had a 'c' program that changed to root, then ran mount for the purpose of mounting a floppy diskette. Any user could run it.

It did not take long for a user to figure out how to abuse the current path setting and the current field seperator variable (SunOS), to get a root shell out of the program.

It is dangerous, and it's hard to think of every situation that puts you at risk.
fmartin@applicatorssales.com
Matt Szary
Advisor

Re: Scripting question from a beginner

I have decided to go for the safest choice. I will download the sudo software and configure. Thank you all for your assistance