Shell Script to add Multiple User Accounts in a System - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

Shell Script to add Multiple User Accounts in a System

Share This
Shell Script to add multiple user accounts in a system
if [ $(id -u) -eq 0 ] then echo User Input echo Enter Session: read ses echo Enter Department: read dept echo Enter Default Password: read pass echo Enter the number of user to be added: read n mkdir /home/$dept mkdir /home/$dept/$ses for ((i=1; i<=n; i++)) do if [ $i -lt 10 ] then stdid=std$ses$dept$i else stdid=std $ses $dept$i fi homedir="/home/$dept/$ses/$stdid" usr=$stdid id $usr &> /dev/null if [ $? -eq 0 ]; then echo "$usr exists..." else useradd -m -d $homedir $usr echo -e "$pass\n$pass" | passwd $usr echo User $usr added successfully. fi done else echo Only root user can add user. fi


Happy Exploring!

No comments:

Post a Comment