script to find files owned by particular user and replace with another uid

JT Moree moreejt at pcxperience.com
Wed Oct 4 17:12:23 MST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Craig White wrote:
> Anybody have a script that finds file say owned by uid=1010 and replace
> owner with uid=1020?

something like

chmod `grep 1020 /etc/passwd | awk -F: '{print $1;}'` \
  `find . -uid 1010`

or to make it reusable

!!!WARNING!!! this is not tested or debugged.  I just wrote it.

#!/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

chmod `grep $USER1 /etc/passwd | awk -F: '{print $1;}'` \
  `find $MYPATH -uid $UID2`

- --
JT Morée
PC Xperience, Inc.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFJE3n1JwGi/ukQqERAldqAKCSZKH0uVc91vDJEbHkhYqwKNvTugCg4dCi
DNIFNv7redWR6d8IWlNPO48=
=S8/U
-----END PGP SIGNATURE-----

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.



More information about the PLUG-discuss mailing list