Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Greg Wooledge
On Sat, Aug 26, 2023 at 06:42:42PM -0400, Karl Vogel wrote: > If you're running bash, the safest way to find your current working > directory is capturing the output from /bin/pwd. Symlinked directories > can surprise you: > > me$ cd > > me$ ls -ldF today > lrwxr-xr-x 1 me mis 18

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Karl Vogel
On Sat, Aug 26, 2023 at 12:09:57PM -0400, Tom Browder wrote: > Excellent mind-reading, Greg! So to use your line I will put in that dir: > "cd /required-dir || exit" > > Thanks so much. And thanks to all others who responded. If you're running bash, the safest way to find your current

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread tomas
On Sat, Aug 26, 2023 at 01:54:41PM -0500, Tom Browder wrote: > On Sat, Aug 26, 2023 at 10:42 wrote: [...] > > Basically it is not possible to find out [...] > As I think I replied earier, I am now checking the script is in the > required directory in order to be executed (by the root user)

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Tom Browder
On Sat, Aug 26, 2023 at 10:42 wrote: > On Sat, Aug 26, 2023 at 04:45:54PM +0200, DdB wrote: > > Am 26.08.2023 um 16:25 schrieb Tom Browder: > > > Is there a way to distinguish whether 'sudo -i' was used or not? > > > > > Sorry, i am not an expert on this. But ... since years i am using this > >

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Nate Bargmann
* On 2023 26 Aug 11:10 -0500, Tom Browder wrote: > On Sat, Aug 26, 2023 at 10:57 Greg Wooledge wrote: > > > On Sat, Aug 26, 2023 at 10:49:45AM -0500, Tom Browder wrote: > > > I would like to know whether 'sudo -i' or 'sudo -s' was used. > > ... > > > In fact, I suspect "I need to know if the

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread tomas
On Sat, Aug 26, 2023 at 11:56:27AM -0400, Greg Wooledge wrote: > On Sat, Aug 26, 2023 at 10:49:45AM -0500, Tom Browder wrote: > > I would like to know whether 'sudo -i' or 'sudo -s' was used. > > That's STILL an X-Y problem. > > > The reason is > > to know if the cwd is set to '/root' or '.'

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Michael Kjörling
On 26 Aug 2023 11:56 -0400, from g...@wooledge.org (Greg Wooledge): > You don't actually need to know what was typed. And even being able to answer the question "how was sudo executed" doesn't solve the problem of ensuring that the script is executing within a particular directory. All it takes

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Tom Browder
On Sat, Aug 26, 2023 at 10:57 Greg Wooledge wrote: > On Sat, Aug 26, 2023 at 10:49:45AM -0500, Tom Browder wrote: > > I would like to know whether 'sudo -i' or 'sudo -s' was used. ... > In fact, I suspect "I need to know if the cwd is /root" is STILL an X-Y > problem. It's sounding like "I

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Greg Wooledge
On Sat, Aug 26, 2023 at 10:49:45AM -0500, Tom Browder wrote: > I would like to know whether 'sudo -i' or 'sudo -s' was used. That's STILL an X-Y problem. > The reason is > to know if the cwd is set to '/root' or '.' It's critical for the script > execution Oh? Then just look at the current

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Tom Browder
On Sat, Aug 26, 2023 at 09:32 Roberto C. Sánchez wrote: > On Sat, Aug 26, 2023 at 09:25:10AM -0500, Tom Browder wrote: > >In a previous thread it was shown how to detect a SUDO_USER in a bash > >shell. > >Is there a way to distinguish whether 'sudo -i' was used or not? I would like

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread tomas
On Sat, Aug 26, 2023 at 04:45:54PM +0200, DdB wrote: > Am 26.08.2023 um 16:25 schrieb Tom Browder: > > Is there a way to distinguish whether 'sudo -i' was used or not? > > > Sorry, i am not an expert on this. But ... since years i am using this > to check for it: > > > # if `echo $HOME` is not

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Alain D D Williams
On Sat, Aug 26, 2023 at 09:25:10AM -0500, Tom Browder wrote: > In a previous thread it was shown how to detect a SUDO_USER in a bash shell. > > Is there a way to distinguish whether 'sudo -i' was used or not? I have not tested this but if bash was interactive you will find a .bash_history file

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread DdB
Am 26.08.2023 um 16:25 schrieb Tom Browder: > Is there a way to distinguish whether 'sudo -i' was used or not? > Sorry, i am not an expert on this. But ... since years i am using this to check for it: > # if `echo $HOME` is not "/root" or the working dir (pwd) is not "/root", > then this was

Re: Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Roberto C . Sánchez
On Sat, Aug 26, 2023 at 09:25:10AM -0500, Tom Browder wrote: >In a previous thread it was shown how to detect a SUDO_USER in a bash >shell. >Is there a way to distinguish whether 'sudo -i' was used or not? >Thanks. >-Tom The SUDO_COMMAND environment variable would report

Using the bash shell: determine if the root user used 'sudo -i'

2023-08-26 Thread Tom Browder
In a previous thread it was shown how to detect a SUDO_USER in a bash shell. Is there a way to distinguish whether 'sudo -i' was used or not? Thanks. -Tom