LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   bash-script question: How to start a user A's process from other users? (https://www.linuxquestions.org/questions/linux-software-2/bash-script-question-how-to-start-a-user-a%27s-process-from-other-users-828558/)

thomas2004ch 08-26-2010 04:12 AM

bash-script question: How to start a user A's process from other users?
 
A Tomcat server is installed under user A. Now I am going to write a script which will start this Tomcat server. And this script can be executed from other users (from there account). And if other user run this script, the process ID should be of user A, so that user A can start or stop this process any time.

This means, at the beginning of the script I have set the process ID as user A. How to do this?

Regards

evo2 08-26-2010 05:43 AM

The switch user: su command.

Cheers,

Evo2.

thomas2004ch 08-26-2010 07:48 AM

My script startAll.sh looks as follow:

Quote:

#!/bin/bash

TOMCAT_USER=tomcat

echo $TOMCAT_USER

TOMCAT_HOME=${TOMCAT_HOME:-"/opt/jboss/tomcat"}

SUBIT="su - $TOMCAT_USER -c "

$TOMCAT_HOME/apache-tomcat-5.5.23/bin/startup.sh

I login as root. I start the script with:
Quote:

/opt/jboss/tomcat/startAll.sh

The Tomcat cab be started but the porcess ID is not the user A but root.

Any mistake in the script?

evo2 08-26-2010 08:13 AM

I guess the last line in your script should be something like:

Code:

$SUBIT $TOMCAT_HOME/apache-tomcat-5.5.23/bin/startup.sh
Evo2.

thomas2004ch 08-26-2010 08:28 AM

bingo!

evo2 08-26-2010 08:44 AM

Excellent. Glad I could help.

Could you mark the thread as [solved]?

Cheers,

Evo2.

thomas2004ch 08-26-2010 09:01 AM

Hi,

Before I mark this as solved, I have a further question:

When I run this script under root, it doesn't ask me for password. But when I run this under user A, it ask me for the password.

This script is located under "/opt/jboss/tomcat" where is user A's region. The user A can run all execute files without entering any password. But it's now not the case.

Is it possible to run the script under user A without asking for password?

Besides, I change the script as follow:
Quote:

#!/bin/bash

TOMCAT_USER=tomcat

echo $TOMCAT_USER

TOMCAT_HOME=${TOMCAT_HOME:-"/opt/jboss/tomcat"}

if [ "$TOMCAT_USER" = "RUNASIS" ]; then
SUBIT=""
else
SUBIT="su - $TOMCAT_USER -c "
fi

$SUBIT $TOMCAT_HOME/apache-tomcat-5.5.23/bin/startup.sh

evo2 08-26-2010 09:22 AM

Quote:

Originally Posted by thomas2004ch (Post 4078477)
When I run this script under root, it doesn't ask me for password. But when I run this under user A, it ask me for the password.

Only, root can su to a random user without a password. Kind of the point of having different user accounts.

Evo2.

PS. There are ways around this eg suid bits and sudo, but both have security implications.


All times are GMT -5. The time now is 12:59 PM.