The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
root executes a script as another user ravi.sri24 Shell Programming and Scripting 9 02-11-2009 10:43 AM
As root , running script as different user with su - problem dbsupp Shell Programming and Scripting 4 12-18-2008 01:28 AM
login into root from user and execute command through script pradeepreddy Shell Programming and Scripting 6 08-29-2008 03:49 AM
run a script on logout by a non-root user harsha10 Shell Programming and Scripting 6 06-16-2008 04:14 PM
root executes a script as another user tads98 Shell Programming and Scripting 1 05-17-2005 09:54 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-08-2009
chipmunken chipmunken is offline
Registered User
  
 

Join Date: Jun 2009
Location: sweden, stockholm
Posts: 10
Question exec script as user on boot not root

Is there a way to change a process owned by root to be owned by another user. I am interested in finding out if there is a way to put a script in /etc/rc2.d that will start up automatically on reboot that will not be owned by root

This is for security reasons.. The Service that runs on my server recomends that I dont run it as root..
Im at the office right now and I have the script on my home computer, if needed I can post it. But Im merly intressted if its possible and what command exec´s stuff as an assigned user. root -> run startTS.sh as user seb
  #2 (permalink)  
Old 07-08-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,123
Hi.

I don't suppose you can change the uid of a running process, but to run something at startup from /etc/rc.d, as a different user, use "su"


Code:
man su

  #3 (permalink)  
Old 07-08-2009
chipmunken chipmunken is offline
Registered User
  
 

Join Date: Jun 2009
Location: sweden, stockholm
Posts: 10
ofc... its always the simplest solution...
Then Ill add
PHP Code:
su seb 
In the beginning of the script so the command that starts the service is run as user seb
For some reason I dident think logging on as a normal user at that stage worked. Kinda stupid now when I think about it. Heh thank you
  #4 (permalink)  
Old 07-08-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,184
Within the startup script /etc/rc2.d/Snnnxxxxx execute a script in another directory to do what you want.


Code:
su seb -c "script to be executed"

BTW. On many unixes rc3 is the place to start user applications (not rc2).
  #5 (permalink)  
Old 07-09-2009
chipmunken chipmunken is offline
Registered User
  
 

Join Date: Jun 2009
Location: sweden, stockholm
Posts: 10
Thank you methyl. As you realise this is my first on boot script. I have done a handfull of diffrent scripts that manualy exec when thay are needed..

Ok so I will make a script in /etc/rc2.d/
PHP Code:
su seb -"/home/seb/tss/startservice.sh" 
Did I understand you correct in this matter?
  #6 (permalink)  
Old 07-09-2009
scottn scottn is offline Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,123
Hi.

Yes, exactly.

I would run it with "su -"


Code:
su - seb -c "/home/seb/tss/startservice.sh"

That way you get seb's environment too.

If you have a method to stop the application when you shutdown, don't forget to create a Knnnnnnn script too.

(the Snnnnn and Knnnnn scripts are often generic...)


Code:
case "$1" in
start )
        startsrc -g ssh
        ;;
stop )
        stopsrc -g ssh
        ;;
* )
        echo "Usage: $0 (start | stop)"
        exit 1
esac

The number you use for your S and K scripts determines the order in which your script is executed, so make sure everything else your application needs (i.e. Oracle, or whatever) is started before you start your application.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0