# batch add users



## ccaptainhastings3 (May 18, 2010)

Is it possible with pw to batch add say 200 users in the form of
user1
user2

up to user200 with random 6 char passwords. I need home creating too.
Any pointers welcome
Thank you


----------



## ccaptainhastings3 (May 18, 2010)

ah found this link which has some examples
http://www.perlcode.org/tutorials/sysadmin/managing_users.pod


```
#!/usr/local/bin/perl -w
    use strict;

    ## create accounts for user_1 .. user_300
    for my $n ( 1..300 ) {
        system('pw', 'user', 'add', '-n', "user_$n");
    }
```

Just need the -m option and get a random password in there


----------



## SirDice (May 18, 2010)

Yes, it's possible. Just create a shell script that does it for you.


----------



## crsd (May 18, 2010)

```
for i in `jot 200 1 200`; do pw useradd user$i -g users -s /bin/tcsh -d /home/user$i -w random -m; done
```


----------



## ccaptainhastings3 (May 20, 2010)

Cheers folks in the end I got this to work

```
i=200; while [ $i -gt 0 ]; do pw user add -n "free$i" -g users -s /bin/tcsh -w random -m; \
    i=`expr $i - 1`; done
```

Using a bit off http://www.perlcode.org/tutorials/sysadmin/managing_users.pod and some of crsd's advice. That random switch in pw was very handy


----------

