Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have been trying to find a script to do the following:
1) open text file containing user list
2) test to see if directory already exists (/directory/username)
3) if not exist, create directory (/directory/username)
4) chmod directory
5) do until EOFAny ideas, resources, pieces would be greatly appreciated.
Thanks,

Can be quite easily done in perl (my preferred scripting language when it comes to text files) and very possibly in bash too.
The perl script would probably go along the lines of:
open text file as an array (@names?)
foreach @names {
print `mkdir /home/$_`;
(if the folder is already there it will just fail to create it)
print `chmod $_ /home/$_`;
}That's about it....it's not a working script but should give you a starting point. More help on a perl script can be supplied if you want.

Here is what I developed:
#!/bin/bash
# script to make user home directories
#DATA1=/dir1/users.txt
DATA2=/dir1/user2.txt
DEST=/dir1/homedeclare -a userarray
declare -a delarraydelarray=() #array of directories to delete (system accounts, etc.)
cat "$DATA1" | tr '\n' ' ' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'> $DATA2
read -a userarray < $DATA2
for user1 in "${userarray[@]}"
{
mkdir $DEST/$user1
chmod 777 $DEST/$user1
echo "$user1 's home directory created"
}for user2 in "${delarray[@]}"
{
rm -rf $DEST/*$user2*
}Not bad for one hours research and work.

uhm, am i missing something or can this be achieved much easier?
#!/bin/bash
LIST=/path/to/listcreate() {
mkdir $i && chmod 755 $i
}for i in `cat $LIST`; do
if [ ! -a $i ]; then
create
echo "created $i"
else
echo "$i exists"
fi
done

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |