[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Root access in subshell
From: |
Bob Proulx |
Subject: |
Re: [Help-bash] Root access in subshell |
Date: |
Mon, 3 Feb 2014 17:32:31 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Richard Taubo wrote:
> Seth David Schoen wrote:
> > Richard Taubo writes:
> >
> >> I was actually trying to do the following (using $ as the prompt):
> >> $ OldIFS=$IFS; IFS=$'\n'; \
> >> for i in $(cat /etc/passwd); do \
> >> split_word=":"; my_user="${i%%$split_word*}";\
> >> if [[ "$my_user" != "root" && "$my_user" != “bin" ]]; then \
> >> printf "%s\n" "------- Finding files by user: $my_user";\
> >> find / -user $my_user -not -path "/proc/*" -print -quit;\
> >> fi;\
> >> done;\
> >> IFS=$OldIFS;
You say "Finding files" but doesn't the -print -quit only print one
file and then quit?
> > If you're up for using external Unix commands instead of shell
> > builtins, you can make this a bit more concise:
> >
> > egrep -v '^(root|bin):' /etc/passwd | cut -d: -f1 | while read i; do
> > printf "%s\n" "------- Finding files by user: $i"
> > find / -user "$i" -not -path "/proc/*" -print -quit
> > fi
> >
> > You could also save one byte (and one subprocess) by using awk:
> >
> > awk -F: '!/^(root|bin):/ {print $1}' /etc/passwd
>
> Thanks, those are good alternatives!
I would prefer Seth's awk solution. With -F: it just works so nicely.
But reading the /etc/passwd file can be done internally to the shell
too. Here is an example.
#!/bin/sh
IFS=:
while read user pass uid gid gecos home shell; do
printf "%s\n" "------- Finding file by user: $user"
find / -user "$user" -not -path "/proc/*" -print -quit
done < /etc/passwd
exit 0
I might be inclined to use find -xdev though. It all depends.
Definitely in an nfs environment I would.
Bob
Re: [Help-bash] Root access in subshell, Chris Down, 2014/02/03
Re: [Help-bash] Root access in subshell, Seth David Schoen, 2014/02/03
Re: [Help-bash] Root access in subshell, Richard Taubo, 2014/02/04