Thursday, May 19, 2011

Adding Multiple Users Script

Multiple User Add Script:
The script reads from file containing first field as "User ID", second field as "First Name" and third field as "Last Name":

export USER=null;
export NAME=null;
/bin/cp -p /etc/passwd /etc/passwd.$(date +%d%m%Y);
/bin/cp -p /etc/sudoers /etc/sudoers.$(date +%d%m%Y);
export NUM=`cat /var/tmp/useradd.txt|wc -l`;
for ((i = 1; i <= $NUM; i++));
export USER=`/usr/bin/head -$i /var/tmp/useradd.txt|tail -1|awk '{print $1}'`;
export NAME=`/usr/bin/head -$i /var/tmp/useradd.txt|tail -1|awk '{print $2" "$3}'`;
/usr/sbin/useradd -c "$NAME" -m -d /home/$USER -s /bin/bash $USER;
/bin/echo 'PASSWORD' |passwd --stdin $USER;
/usr/bin/chage -d 0 -M 90 $USER;
echo "$USER ALL=(ALL) ALL" >> /etc/sudoers;

No comments:

Post a Comment