We are really pushing the limits of my limited bash scripting knowledge now!
Try this for a quick fix and see if it works. Guess I will just have to go out a get a book on bash scripting. ;D
#!/bin/bash
#Define Variables
READ_FILE=/tmp/new.webhost
#Add users
cat $READ_FILE | while read line
do
username=`echo $line | cut -f1 -d":"`
userweb=`echo $line | cut -f2 -d":"`
userpass=`echo $line | cut -f3 -d":"`
echo "Adding user: " $username
/usr/sbin/useradd -g 200 -s /bin/false -d /webs/$userweb $username
/bin/chmod -R 755 $userweb
/bin/chown -R $username $userweb
/bin/chgrp -R webhosting $userweb
echo $userpass | passwd $username --stdin
echo "<VirtualHost 216.110.5.16>" >> /etc/httpd/conf/named-virtual.conf
echo "DocumentRoot /webs/$userweb" >> /etc/httpd/conf/named-virtual.conf
echo "ServerName $userweb" >> /etc/httpd/conf/named-virtual.conf
echo "</VirtualHost>" >> /etc/httpd/conf/named-virtual.conf
done
#I put this here assuming you can restart once after all the new users have been added.
/etc/rc.d/init.d/httpd restart
exit 0


Reply With Quote

Bookmarks