Sourcing as root automatically


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sourcing as root automatically
# 1  
Old 01-05-2013
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.
# 2  
Old 01-05-2013
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.
# 3  
Old 01-05-2013
Quote:
Originally Posted by RudiC
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sourcing variables from another script

My manager required that i keep the hostnames and username and password in a separate file when creating my sftp script. (Don't mention passwords and sftp...I've talk to him about this several times) I have a list of hostnames that have to be read in a loop in my main script. I don't know... (3 Replies)
Discussion started by: MJCreations
3 Replies

2. Shell Programming and Scripting

How to run script automatically on reboot as root user?

Hi friends,,, I am running one server on Ubuntu 12.04 LTS 32-bit, some times my pc restarts automatically, with no reason, I have a script to start server which requires root password. in this directory /myserver/start_server.sh How can I do this ? and some scripts I am having that I... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

3. Red Hat

Crontab sourcing PATH?

Hi, Im trying to run script A which requires path /sbin. I have a crontab entry to run script A every 10 minutes. Script A is executed fine by cron, but because script A requires /sbin in its path it fails to run. My situation is script A get overwritten from time to time so I can't modify... (4 Replies)
Discussion started by: wilsonee
4 Replies

4. Solaris

Migration of system having UFS root FS with zones root to ZFS root FS

Hi All After downloading ZFS documentation from oracle site, I am able to successfully migrate UFS root FS without zones to ZFS root FS. But in case of UFS root file system with zones , I am successfully able to migrate global zone to zfs root file system but zone are still in UFS root file... (2 Replies)
Discussion started by: sb200
2 Replies

5. Shell Programming and Scripting

sourcing .profile for other users

Hi Team, Thank you for your time. i have a situation where the user IDs of the applicatio users have been locked down to Read only. Hence I am writing a script to invoke their old .profile every time they login. My problem is : when i run . $userpath/.profile from within the ksh script... (9 Replies)
Discussion started by: anitha111
9 Replies

6. Solaris

Root file system automatically reduced from 90 to 40%

Greetings. i have solaris 9. I had a problem with root file system day before yesterday when it got 100% full, i reduced it to 90% but then after one day it was automatically reduced to 40%!!! no human intervention was done. no reboot done. Last time when i checked in proc FS there were a lot... (3 Replies)
Discussion started by: mr_os
3 Replies

7. Solaris

rootsh on Solaris 10 is not sourcing root's .profile

I'm attempting to setup rootsh on Solaris 10 to log the activity of users who require root access. However it does not appear to be sourcing root's .profile file even when run with the '-i' option. I was wondering if anybody else has run into this and might have a solution. Thank you. (9 Replies)
Discussion started by: kungfusnwbrdr
9 Replies

8. Shell Programming and Scripting

Change root password automatically

I need to change root password automatically in some servers all three months. I want to run this process in one of the servers and reply it to the others. The password must be known by the administrator. (3 Replies)
Discussion started by: Alrica
3 Replies

9. UNIX for Dummies Questions & Answers

sourcing the .bashrc

Hello, I am quite new to Linux... I need to set some aliases and I can't get it to work. Can somebody tell me what's wrong? I modified the .bashrc file in my home directory. I added: alias pmv= '/home/vera/MGLTools-1.4.5/share/bin/pmv' saved it and ran source .bashrc The shell... (3 Replies)
Discussion started by: Nusy
3 Replies

10. UNIX for Dummies Questions & Answers

arguments in sourcing file

Hello ! I want to make a script like that. #!/bin/csh -f setenv toto me setenv titi you setenv tata $1 in which tata is visible outside the script, after sourcing this script. It seems that you can only do source script and not source script arg How can I do that ? ... (4 Replies)
Discussion started by: Nathe
4 Replies
Login or Register to Ask a Question