PDA

View Full Version : shell script, create bulk account


webelo
4th January 2008, 10:03
hello there,

was wondering if there is or if its easy to create a shell script that will let me add domains to a server in bulk (like 200 domain), I want to get a list of domain in a .data file, the script should read the file, create the usernames and group for each domain, set a default password, add to virtualhosting apache, create user folder /home/<user>/

Is this possible? Is there anything like this out there?

I don't know, maybe it can run like this...
#!/bin/sh
cat domain.data | \
while read domain
do
echo "Found domain: $domain"
done
---------------

But than have to do the rest :(

Can anyone help?


Thanks

devnull3d
16th January 2008, 12:59
That shouldn't be too hard even in bash but I'd perfer to use perl. I'll attempt to throw something together (untested)

#!/bin/bash
for domain in `cat domain`
do
mkdir /home/$domain
chown apache:apache /home/$domain
cat apache_vhost_template | sed "s/domain_template/$domain" >> /etc/apache2/sites-enabled/000-default
done

Not exactly what you asked for but it should do the trick, of course you need to create apache_vhost_template yourself, it should look something like this

$ cat apache_vhost_template
<VirtualHost *:80>
ServerName domain_template
DocumentRoot /home/domain_template
</VirtualHost>