Friday, September 16, 2005

Produce a list of the home directories of the listed users.

> ********************************************* #!/bin/sh # HomeDir [user]...
> ## Produce a list of the home directories of the listed users. # If no users
> are given, produce all home directories.

Hi,
Try this script.....assuming ur group_id is stored in $grp
IFS='^J'
for i in `cat /etc/passwd`
do
if [ `echo $i|cut -d: -f4` -eq $grp ];then
user=`echo $i|cut -d: -f1`
mkdir /home/$user
fi
done
Hope it helps.........note that u can't simply cut from password file
otherwise u will be creating directory for system accounts too.
n

Something like this should work:

cat /etc/passwd | awk -F: '{print "mkdir "$6" && chown "$1":"$4" "$6}' | sh

Try it without the "|sh" first to see if it looks correct. It should attempt
to create the directory, but if it already exists, will get an error and not
do the 'chown'. If it doesn't exist (and succeeds), it should do the chown.

0 Comments:

Post a Comment

<< Home