Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #261224
| From | Karl Vogel <vogelke@pobox.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Using the bash shell: determine if the root user used 'sudo -i' |
| Date | 2023-08-27 01:10 +0200 |
| Message-ID | <H7azL-4CVP-7@gated-at.bofh.it> (permalink) |
| References | <H72sy-4xRT-5@gated-at.bofh.it> <H72Cd-4xUZ-3@gated-at.bofh.it> <H73RD-4yAo-1@gated-at.bofh.it> <H73RD-4yAo-5@gated-at.bofh.it> <H741j-4yT0-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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 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 Aug 26 00:03 today@ -> notebook/2023/0826
me$ cd today
me$ pwd
/home/me/today
me$ /bin/pwd
/home/me/notebook/2023/0826
me$ echo $PWD
/home/me/today
If you want to know why you had an early exit:
me$ cat try
#!/usr/bin/env bash
# try: test logging.
export PATH=/usr/local/bin:/bin:/usr/bin
set -o nounset # check for unbound variables.
tag=${0##*/}
umask 022
# Test file descriptor 2 for interactive or cron use.
test -t 2
case "$?" in
0) logmsg () { echo "$(date '+%F %T') $tag: $@"; } ;;
*) logmsg () { logger -t $tag "$@"; } ;;
esac
warn () { logmsg "WARN: $@" ; }
die () { logmsg "FATAL: $@"; exit 1 ; }
# Real work starts here.
case "$#" in
0) die "need a directory" ;;
*) dir="$1" ;;
esac
test -d "$dir" || die "$dir: not a directory"
cd "$dir" || die "$dir: cannot cd"
cwd=$(/bin/pwd)
logmsg "start working in $cwd"
exit 0
On FreeBSD, you can use "daemon" to run something detached from the
controlling terminal, which simulates running a cron job:
me$ ls -ldF /etc /var/authpf
drwxr-xr-x 27 root wheel 120 26-Aug-2023 07:55:02 /etc/
drwxrwx--- 2 root authpf 2 05-Jul-2019 00:45:45 /var/authpf/
me$ ./try /etc
2023-08-26 18:31:54 try: start working in /etc
me$ daemon -f $PWD/try /etc
me$ daemon -f $PWD/try /var/authpf
me$ tail -2 /var/log/syslog
Aug 26 18:19:17 myhost try: start working in /etc
Aug 26 18:19:19 myhost try: FATAL: /var/authpf: cannot cd
Hope this helps.
--
Karl Vogel I don't speak for anyone but myself.
Oh, my darlin' had bronchitis and she barfed up half a lung,
what came up looked quite amazing when she rolled it on her tongue.
--sung to the tune of "My Darling Clementine"
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using the bash shell: determine if the root user used 'sudo -i' Tom Browder <tom.browder@gmail.com> - 2023-08-26 16:30 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Roberto C. Sánchez <roberto@debian.org> - 2023-08-26 16:40 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Tom Browder <tom.browder@gmail.com> - 2023-08-26 18:00 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Greg Wooledge <greg@wooledge.org> - 2023-08-26 18:00 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Tom Browder <tom.browder@gmail.com> - 2023-08-26 18:10 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Nate Bargmann <n0nb@n0nb.us> - 2023-08-26 19:20 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Karl Vogel <vogelke@pobox.com> - 2023-08-27 01:10 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Greg Wooledge <greg@wooledge.org> - 2023-08-27 01:30 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Michael Kjörling <2695bd53d63c@ewoof.net> - 2023-08-26 18:20 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' <tomas@tuxteam.de> - 2023-08-26 18:40 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Alain D D Williams <addw@phcomp.co.uk> - 2023-08-26 17:30 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' <tomas@tuxteam.de> - 2023-08-26 17:50 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' Tom Browder <tom.browder@gmail.com> - 2023-08-26 21:00 +0200
Re: Using the bash shell: determine if the root user used 'sudo -i' tomas@tuxteam.de - 2023-08-26 21:20 +0200
csiph-web