1753667 Members
5619 Online
108799 Solutions
New Discussion юеВ

Re: killproc in .profile

 
SOLVED
Go to solution
Mike Kuhar
Advisor

killproc in .profile

A user has installed the killproc function, which is in most startup scripts, copied verbatim in their ~/.profile. This doesn't seem to be the wisest think in the world to do, My question is, is it acceptable to put shell script code directly into ~/.profile? -mk
6 REPLIES 6
David Burgess
Esteemed Contributor

Re: killproc in .profile

Mike,

.profile and profile are scripts. You could run a script from the users .profile using

sh <scriptname>

or

exec <scriptname>

exec will overwrite the parent pid thus logging out the user when the script completes. I've had users .profiles run apps using exec and then log them out when they exit the app to stop them getting a shell.

Regards,

Dave.
Mike Kuhar
Advisor

Re: killproc in .profile

I'm not asking whether I can call a script from .profile. I'm asking whether it is good practice to put inline shell code in .profile, such as:

killproc() {
pid=`ps -e | awk '$NF~/'"$1"'/ {print $1}'`
if [ "X$pid" != "X"]; then
if kill "$pid"; then
echo "$1 stopped"
else
rval=1
echo "Unable to stop $1"
fi
fi
}
David Burgess
Esteemed Contributor

Re: killproc in .profile

Shell code in the .profile is ok. I can't see why you would want to kill $1 from the .profile as you don't pass parameters to it.

Dave.
Mike Kuhar
Advisor

Re: killproc in .profile

Thanks for the reply, again, Dave. I think that this is my point. Before I tell the user to get it out of his .profile, I just want to make sure I have all facts.
David Burgess
Esteemed Contributor
Solution

Re: killproc in .profile

Mike,

Yep makes sense. You don't want that in their .profile especially if they have high system rights. You don't know what they might do when they login or someone su's to their account. If they don't play ball make it root owned and read only for them. That'll stop them!

Regards,

Dave.
A. Clay Stephenson
Acclaimed Contributor

Re: killproc in .profile

Without knowing more, it's not possible to answer. Note that in this instance killproc is a function so unless the function is actually invoked, it does nothing. The preferred method for using code like this is to include it in the foreground process via the "." command.

If it ain't broke, I can fix that.