1

In Ubuntu 12.04, I'm having difficulties creating a script (since I'm not experienced with it), and is assigned to add multiple users from a list of names in file usernames.txt.

  1. The users will have url: hxxp://hostname/~userN, where N is integer.
  2. The users can SSH with password which is the same with the username.
  3. The users will have file /home/userN/public_html/index.html consist of text: Hello userN
  4. The users also have a database with name & password is userN.

I have configured apache userdir, mysql. Thanks for any helps...

Bonn
  • 43
  • 1
  • 8

1 Answers1

1
#!/bin/sh

echo '[mysql]' > ~/.my.cnf
echo -e 'user\t\t= root' >> ~/.my.cnf
echo -e 'password\t= <root password>' >> ~/.my.cnf

while read u; do 
    # 1. config in Apache

    # 2. DON'T DO THIS. Why do you want to give ssh access to these users?
    /usr/sbin/useradd -m -p $(perl -e 'print crypt($ARGV[0], "password")' $u) $u

    # 3. Check to see if `public_html` directory exist
    [ ! -d /home/$u/public_html ] && mkdir /home/$u/public_html
    echo 'Hello '$u > /home/$u/public_html/index.html

    # 4. Make sure that you can login to MySQL without prompting for password
    mysql -e "create database $u; grant all privileges on $u.* to $u@'localhost' identified by '$u';"
done < usernames.txt
quanta
  • 50,327
  • 19
  • 152
  • 213