root executes a script as another user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting root executes a script as another user
# 1  
Old 02-10-2009
root executes a script as another user

Hi All,
Am using the below command to start my application using the root user
su - bin -c "/home/bin/test/start.sh"

but am getting the error becaue i have set some environment varibales in bin's .profile

when i execute the command start.sh by logging directly into bin account it's working fine

But where as if i ran the above command using the root user am getting error seems it's not loading the bin's .profile file

Please advise me how to load the bin's profile while using the su
# 2  
Old 02-10-2009
One way is to "source" the .profile of bin in your script, something like:

Code:
. /home/bin/.profile

Regards
# 3  
Old 02-10-2009
Quote:
Originally Posted by Franklin52
One way is to "source" the .profile of bin in your script, something like:

Code:
. /home/bin/.profile

Regards
Thanks for the reply, I have tried the way you suggested but no luck still it's not taking the bin's environment varibales
# 4  
Old 02-10-2009
Quote:
Originally Posted by ravi.sri24
Thanks for the reply, I have tried the way you suggested but no luck still it's not taking the bin's environment varibales
Should work, did you used the right path? Have you placed the line above the other commands in your script?

Regards
# 5  
Old 02-10-2009
Quote:
Originally Posted by Franklin52
Should work, did you used the right path? Have you placed the line above the other commands in your script?

Regards
Yes i have placed properly only, below is the command

./home/bin/.profile

su - bin -c "/opt/bin/test/receiver/start.sh
# 6  
Old 02-11-2009
There's must be a space between the dot and the slash:

Code:
. /home/bin/.profile

Regards
# 7  
Old 02-11-2009
Quote:
Originally Posted by Franklin52
There's must be a space between the dot and the slash:

Code:
. /home/bin/.profile

Regards
Yes i have tired by giving space also but still no luck
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. Shell Programming and Scripting

Switch between root and user in the same script.

I am writing a korn shell script where i need to switch to root in between and again exit from root to normal user and continue other commands. Is that possible to switch between these two in the same script? (1 Reply)
Discussion started by: santosh2626
1 Replies

3. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

4. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

5. AIX

what user executes init on boot?

I have a command in init that trys to start a daemon and open a log, but a get an error error that the file access permissions do not allow the specified action. My permissions on the log file are: -rw-r--r-- 1 root system 4434 Mar 22 15:13 dsmerror.log The logfile is written to... (2 Replies)
Discussion started by: pong3d
2 Replies

6. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

7. Shell Programming and Scripting

Create a script that executes when a user attempts to delete history logs

Hi, I have a linux redhat 9 server and I am concerned about the security on that server. I would like to be able to write a script that records all the commands that were typed at the command prompt before the user calls the 'history -c' command and deletes all the history. I was thinking about... (4 Replies)
Discussion started by: mishkamima
4 Replies

8. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

9. Shell Programming and Scripting

As root , running script as different user with su - problem

Dear All I am running into a situation where I am running a script as another user lets say oracle using su command as below, and the script fails because the .profile of oracle is not executed so the environment variables are not set. cat /etc/passwd | grep oracle... (4 Replies)
Discussion started by: dbsupp
4 Replies

10. Shell Programming and Scripting

root executes a script as another user

we have this script that stops, starts and monitor process scheduler. prcs_control. this script runs perfectly when executed by ps_user. we are now creating a new script that will run this script and is executed by root. this script needs to execute the prcs_control as ps_user because root can... (1 Reply)
Discussion started by: tads98
1 Replies
Login or Register to Ask a Question