sudo needs to source target user's .shrc


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sudo needs to source target user's .shrc
# 1  
Old 08-11-2011
sudo needs to source target user's .shrc

I'm configuring a sudo Runas_Alias in the sudoers file on a hp-ux 11.31 system. The goal is to allow some hp-ux accounts to sudo to a service account and run commands as that user. Here's the related sudoers entries:

User_Alias DMSTAFF = %dmstaff
Runas_Alias DMALIAS = dmadmin
DMSTAFF ALL = (DMALIAS) NOPASSWD: ALL

For example, testuser1 belongs to the dmstaff hp-ux group, so he is allowed to run commands as dmadmin like this:

sudo -u dmadmin [some command]
or
sudo -Hu dmadmin [some command] (preserve's target user's home dir)

It works very well and sudo commands are logged to our sudo.log.
However, sudo is not sourcing important env variables that dmadmin requires. These env variables are normally sourced from dmadmin's .shrc file in his home directory.

We can simple allow the users to sudo su - dmadmin by defining a simple Cmnd_Alias, but in that case subsequent commands will not be logged to the sudo.log - a dept. requirement.

Any ideas?
# 2  
Old 08-11-2011
Set the environment vars before you run sudo, and give sudo -E to preserve environment. This may need slight changes in your sudo config to allow the setenv option.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-11-2011
env_file seems to work

I found this code defining env_file for an Runas_Alias in a similar thread. It seems to work pretty well:

Defaults>DMALIAS env_file=/homedir/.shrc
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

2. UNIX for Dummies Questions & Answers

How to count number files successfully copied from source to target location?

Hi Guys, how to count number of files successfully copied while coping files from source to destination path ex:10 files from source to target location copying if 8 files copied successfully then echo successfully copied=8 failure=2 files if two files get error to coping files... (2 Replies)
Discussion started by: sravanreddy
2 Replies

3. Post Here to Contact Site Administrators and Moderators

How to count successfully copy files source to target location with check directory in Linux?

Hi guys...please any one help me .... how to copy files from source to target location if 5 files copied successfully out of 10 files then implement success=10 and if remaining 5 files not copied successfully then count error=5 how to implement this condition with in loop i need code linux... (0 Replies)
Discussion started by: sravanreddy
0 Replies

4. Shell Programming and Scripting

Reconcilations script between Source and Target

Hi, I am new to DB2 and in need of urgent help. Here we have about 100 queries (SQL) that have been manually executed to retrieve totals from different tables and post it to Excel spreadsheet. Is there any way I can create a shell script as a wrapper and execute these queries and create a... (5 Replies)
Discussion started by: bhaskar v
5 Replies

5. Shell Programming and Scripting

Connect to target host from Source host.

Hi All, Need to connect to target host and execute a command and connect back to source host to continue with next set of command execution. Is there a utility/command using which we can connect to target host ? Please suggest. Note: Netezza database is instaled on Linux server. ... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

6. UNIX for Dummies Questions & Answers

[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory?

I have checked the man page ,which says : The -H (HOME) option sets the HOME environment variable to the homedir of the target user (root by default) as specified in passwd(5). By default, sudo does not modify HOME But I have tried below command: #... (1 Reply)
Discussion started by: Michaelw321
1 Replies

7. Shell Programming and Scripting

Shell script to transfer the files from source to target server.

I need to write a shell script to transfer the files every hour from source - target server. The cron job should be running every hour and shouldn't copy already copied files to the remote server ? I was able to write intial script but not able to get the logic for (in the next run it should... (12 Replies)
Discussion started by: radhirk
12 Replies

8. Shell Programming and Scripting

Source and Target count checking

Hi My source database is seibel and the target is oracle. I need to check the count for source query and target query. if it is equal then i need to send and success mail to an email id. If it is not equal need to send an failure mail to an email id. pl let me know about the script in ksh. ... (2 Replies)
Discussion started by: ksmbabu
2 Replies

9. UNIX for Dummies Questions & Answers

vi, c/source/target g?

hi in vi, i have a file and i wanted to replace all wnix to unix. is the below correct. c/wnix/unix g... i have tried , and the above is not right... help? (7 Replies)
Discussion started by: yls177
7 Replies
Login or Register to Ask a Question