#!/bin/bash
# Description:
# Date && Time:2010-12-29 13:04:57
# Author:AIDA_ZYF
# Version:2.6.18-164.el5
NUID=$[`cat /etc/passwd |cut -d: -f3 |grep -v "^65534" |sort -n |tail -1`+1]
NGID=$[`cat /etc/group |cut -d: -f3 |grep -v "^65534" |sort -n |tail -1`+1]
TODAY=$[`date +"%s"`/24/60/60]
show_uname() {
dialog --backtitle "Add a user..." --title "Add a user" --colors --form "\Z1Please input the information of new user.\Z0" 12 40 4 "Username:" 1 1 "" 1 15 15 0
"Fullname:" 2 1 "" 2 15 15 0 "Home Dir:" 3 1 "" 3 15 15 0 "Shell:" 4 1 "" 4 15 15 0 2>/tmp/name.txt
}
show_uname
padd() {
dialog --backtitle "Input a passwd..." --title "Input a passwd" --colors --passwordbox "\Z1Please input a password for the new user.\Z0" 7 40 2>/tmp/pass.txt
mkuser
}
mkuser() {
cp -r /etc/skel/ /home/$a
chown -R $a:$a /home/$a
chmod -R go=--- /home/$a
MYPASS=$[`cat /tmp/pass.txt |grep "^[^[:space:]]"`]
echo "$MYPASS" |passwd --stdin $a &>/dev/null
}
uadd() {
declare a b c d
a=`head -1 /tmp/name.txt`
b=`head -2 /tmp/name.txt |tail -1`
c=`head -3 /tmp/name.txt |tail -1`
d=`tail -1 /tmp/name.txt`
if ! cut -d: -f1 /etc/group |grep "^$a" &>/dev/null ;then
echo "$a:x:$NGID:" >>/etc/group
else
echo "The group $a is exit."
exit 1
fi
if ! cut -d: -f1 /etc/passwd |grep "^$a" /etc/passwd &>/dev/null ;then
echo "$a:x:$NUID:$NGID:$b:$c:$d" >>/etc/passwd
echo "$a:!!:$TODAY:0:99999:7:::" >>/etc/shadow
else
echo "The user $a is exits."
exit 1
fi
wait 1
padd
}
if grep "^/home/[^[:space:]]" /tmp/name.txt &>/dev/null ;then
echo "You are right."
uadd
else
echo "Plaese try again.."
exit 1
fi
阅读(961) | 评论(1) | 转发(0) |