Re: FIXED Re: script to find files owned by particular user …

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Craig White
Date:  
To: Main PLUG discussion list
Subject: Re: FIXED Re: script to find files owned by particular user and replace with another uid
Following up on this weeks question, I ended up using JT's script,
modifying it for the fact that I am using LDAP and therefore, no usable
values in /etc/passwd for me and yes, there was a debug issue, and
finally hoping that it handled some typical filename/folder name issues
- borrowing from Darrin's suggestion. Below is my final script for
anyone who wants to track this...

(btw - getent passwd | grep is universal whereas grep /etc/passwd is
useful for only 1 particular situation)

Thanks JT, Darrin, JD, Kurt (I love this list)

Craig

#!/bin/sh

USER1=$1
USER2=$2
MYPATH=$3

usage()
{
echo "Script to change ownership of files from user X to user Y"
echo "$0 <user1> <user2> [path to search]"
echo
}

echo "Changing files owned by "$USER1
echo "to user "$USER2
echo "In directory "$MYPATH
echo ""

if [ -z "$USER1" ] ; then echo "Invalid user 1"; usage ; exit 1; fi
if [ -z "$USER2" ] ; then echo "Invalid user 2"; usage ; exit 1; fi
if [ -z "$MYPATH" ] ; then echo "Invalid path" ; usage ; exit 1; fi

UID1=`getent passwd |grep $USER1 | awk -F: '{print $3;}' `
UID2=`getent passwd |grep $USER2 | awk -F: '{print $3;}' `

if [ -z "$UID1" ] ; then echo "Invalid user 1"; usage ; exit 1; fi
if [ -z "$UID2" ] ; then echo "Invalid user 2"; usage ; exit 1; fi

find $MYPATH -user $UID1 -exec chown $USER2 {} \;


On Wed, 2006-10-04 at 17:13 -0700, JT Moree wrote:
>
>
> !!!WARNING!!! this is not tested or debugged. I just wrote it.
>
> ARRRGH. I keep typing chmod instead of chown.
>
> #!/bin/sh
>
> USER1=$1
> USER2=$2
> MYPATH=$3
>
> usage()
> {
> echo "Script to change ownership of files from user X to user Y"
> echo "$0 <user1> <user2> [path to search]"
> echo
> }
>
> if [ -z "$USER1" ] ; then echo "Invalid user 1"; usage ; exit 1; fi
> if [ -z "$USER2" ] ; then echo "Invalid user 2"; usage ; exit 1; fi
> if [ -z "$MYPATH" ] ; then MYPATH="./" ; exit 1; fi
>
> UID1=`grep $USER1 /etc/passwd | awk -F: '{print $3;}' `
> UID2=`grep $USER2 /etc/passwd | awk -F: '{print $3;}' `
>
> if [ -z "$UID1" ] ; then echo "Invalid user 1"; usage ; exit 1; fi
> if [ -z "$UID2" ] ; then echo "Invalid user 2"; usage ; exit 1; fi
>
> chown `grep $USER1 /etc/passwd | awk -F: '{print $1;}'` \
> `find $MYPATH -uid $UID2`
>
> - --
> JT Morée
> PC Xperience, Inc.
>
>

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss