help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Root access in subshell


From: Richard Taubo
Subject: Re: [Help-bash] Root access in subshell
Date: Tue, 4 Feb 2014 01:58:59 +0100

On Feb 4, 2014, at 1:32 AM, Bob Proulx <address@hidden> wrote:

> 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?

In this case I am using it to see which users I can remove on the server;
i.e. if a user does not own any files, and it is unlikely that processes will
use this user, I will delete it. 

> 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.

Okay, thanks. I will look into that!

Richard Taubo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]