LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-26-2010, 05:12 AM   #1
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 537

Rep: Reputation: 33
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
 
Old 08-26-2010, 06:43 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,130

Rep: Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482
The switch user: su command.

Cheers,

Evo2.
 
Old 08-26-2010, 08:48 AM   #3
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 537

Original Poster
Rep: Reputation: 33
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?
 
Old 08-26-2010, 09:13 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,130

Rep: Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482
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.
 
1 members found this post helpful.
Old 08-26-2010, 09:28 AM   #5
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 537

Original Poster
Rep: Reputation: 33
bingo!
 
Old 08-26-2010, 09:44 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,130

Rep: Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482
Excellent. Glad I could help.

Could you mark the thread as [solved]?

Cheers,

Evo2.
 
Old 08-26-2010, 10:01 AM   #7
thomas2004ch
Member
 
Registered: Aug 2009
Posts: 537

Original Poster
Rep: Reputation: 33
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

Last edited by thomas2004ch; 08-26-2010 at 10:02 AM.
 
Old 08-26-2010, 10:22 AM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,130

Rep: Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482Reputation: 1482
Quote:
Originally Posted by thomas2004ch View Post
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.

Last edited by evo2; 08-26-2010 at 10:25 AM. Reason: PS
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash shell script to check the if empty files are being created & start the process hussa1n Linux - General 8 06-29-2010 06:49 PM
[SOLVED] bash script - check process is running, if not start zee# Linux - Newbie 8 02-07-2010 06:50 PM
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 07:58 AM
Start a program for a user as root, with process belonging to user gnashley Programming 4 03-19-2007 02:58 PM
BASH script inform user and kill process mounters Programming 3 02-11-2002 05:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration