Chinaunix首页 | 论坛 | 博客
  • 博客访问: 638981
  • 博文数量: 110
  • 博客积分: 3808
  • 博客等级: 中校
  • 技术积分: 1930
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 14:32
个人简介

声的伟大!

文章分类

全部博文(110)

文章存档

2014年(1)

2013年(2)

2012年(12)

2011年(81)

2010年(14)

分类:

2011-01-02 12:52:30

#!/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) |
给主人留下些什么吧!~~

chinaunix网友2011-01-05 11:00:52

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com