I am trying to develop a shell script which creates new users in linux machine. Where username and password are fetched from a config file. Can somebody help me to create a script which creates users with all the usernames in the config file.
My config file contains (myconf.cfg)
username="tempuser"
password="passXXX"
username="newuser"
password="ppwdXXX"
.....
.....
username="lastuser"
password="pass..."
Using a script I am trying to create users with above listed username and password. The script is:
#!/bin/sh
echo "Reading config...." >&2
. /root/Downloads/guest.cfg
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
sudo useradd -m -p $pass $username -s /bin/bash
I am able to create only 1 user with this script (ie lastuser). Can somebody help me to modify the script and config file so that it will create all the users mentioned in the config file. My aim is to keep the script intact and make changes to the config file only. The script should be able to create 'N' number of users listed in the config file.
Thanks in advance.