Results 1 to 5 of 5
Hi,
I have a bash script that need to be run as sudo because it needs to edit system files. This is fine I execute:-
Code:
sudo ./script
Obviously if ...
- 08-26-2011 #1Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
Bash Script run as root but know what user executed script
Hi,
I have a bash script that need to be run as sudo because it needs to edit system files. This is fine I execute:-
Obviously if the script contained:-Code:sudo ./script
It would return:-Code:theuser=`id -u` echo $theuser echo $USER
But lets say I'm logged in as the user 'admin' with ID '1000' and i run:-Code:0 root
How can I get the script to know what the originating user was and somehow assign admin's details to variables in the script to be used later on.Code:sudo ./script
e.g. I want to edit /etc/ssh/sshd_config and add a line AllowUser with the current logged in user. I want the line to read:-
But the script would have to run as root to be able to edit the file.Code:AllowUser admin
Hope this makes sense.
Cheers
Harv
- 08-27-2011 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
- 08-29-2011 #3Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
I would have said "echo $SUDO_UID" but that 'who am i' is cool!
- 08-30-2011 #4Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
They both sound great, I will give them a go, thanks!
- 08-30-2011 #5Just Joined!
- Join Date
- Sep 2010
- Posts
- 8
atreyu: yours does closer to what I want it to do.
Thanks to both!


Reply With Quote
