Sourcing as root automatically | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Sourcing as root automatically

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-05-2013
dasx's Avatar
dasx dasx is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 30 November 2013, 9:14 AM EST
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
Sourcing as root automatically

Hey everyone!

I have my .bash_profile file which is read automatically when I launch Terminal therefore I can run my own functions.

BUT.

When I do:

Code:
sudo -s


Code:
sudo su


Code:
sudo su -

No matter what I do, I can't get the .bash_profile file to be sourced automatically so I end up having to run different commands.

Example: I have this function:


Code:
aaa(){
	if [ `id -u` -eq 0 ]
		then	rm ~/Whatever/*
		else	echo PERMISSION DENIED
	fi
}

Running:

Code:
aaa

Output:

Code:
PERMISSION DENIED

Running:

Code:
sudo aaa

Output:

Code:
sudo: aaa: command not found

So I end up having to type:

Code:
sudo -s
source ~/.bash_profile
aaa

Any possible way I can make shell source .bash_profile automatically when logging as sudo?

Thanks!


P.S: I know I can just add it to the bashrc file in /etc/, I'd just like to avoid that workaround.
Sponsored Links
    #2  
Old 01-05-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 23 April 2014, 4:36 AM EDT
Location: Aachen, Germany
Posts: 3,534
Thanks: 51
Thanked 823 Times in 785 Posts
su - does source the profile as it does a login. But, as you su to another user, it sources that user's profile, so make sure aaa is in root's profile and it will fly.
Sponsored Links
    #3  
Old 01-05-2013
dasx's Avatar
dasx dasx is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 30 November 2013, 9:14 AM EST
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
su - does source the profile as it does a login. But, as you su to another user, it sources that user's profile, so make sure aaa is in root's profile and it will fly.
Yes, I can always put all my functions in the bashrc and be done with it. I just wanna know if there's any way to get the bash_profile sourced when logging in as root.

Thanks!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sourcing .profile for other users anitha111 Shell Programming and Scripting 9 06-16-2011 04:02 PM
Root file system automatically reduced from 90 to 40% mr_os Solaris 3 09-29-2010 01:37 AM
rootsh on Solaris 10 is not sourcing root's .profile kungfusnwbrdr Solaris 9 11-27-2009 10:58 AM
Change root password automatically Alrica Shell Programming and Scripting 3 05-26-2009 04:05 AM
sourcing the .bashrc Nusy UNIX for Dummies Questions & Answers 3 05-27-2008 05:23 PM



All times are GMT -4. The time now is 08:09 AM.