|
发表于 2004-12-20 18:40:07
|
显示全部楼层
- #!/bin/bash
- #
- #.bashrc (Use to add new user for openlab).
- #
- # To prevent the quit for system secrity.
- #
- trap "" 2
- # Modify group, logfile:
- #
- GROUP="users"
- LOGFILE="userlog"
- # main script file
- # Can modify some infomations follow the "echo"
- # eg: welcome informations or error infomatons.
- #
- # Welcome informations
- #
- clear
- echo "-=====================================================================-"
- echo "- W e l c o m e T o T h e O p e n l a b -"
- echo "-=====================================================================-"
- echo
- echo "Please follow the steps to create your own account!"
- for try in 1 2 3 4 5
- do
- echo
- echo -n "Please enter your new own account:"
- read ACC
- ##
- if echo "$ACC" | grep '[^a-z0-9]' > /dev/null
- then
- echo
- echo "name should be all alphanumeric, '-', '_', '.'."
- elif echo "$ACC" | grep '^[a-z]' > /dev/null
- then
- if `adduser "$ACC" -g "$GROUP" -d /"$GROUP"/"$ACC"`
- then
- echo
- echo "Please enter your password, sugessted longer than "6" !!!"
- echo
- passwd $ACC
-
- # Sucessfull infomation
- #
- echo
- echo "Congratulations, your own account was created."
- echo "You should relogin later with your new account."
-
- # userlog, contains account created in the system
- #
- echo "$ACC" | cat >> "$LOGFILE"
- # standby 5 seconds
- #
- sleep 5
- exit
- else :
- fi
- else
- echo
- echo "account must begin with lowercase character."
- fi
- done
- # Many faild times or too errors to create new account.
- #
- echo "You are trying too many times."
- echo "Please try it next time."
- sleep 4
- exit
复制代码
不知这个能行不?
很早以前写的一个,在实验室用过.可以对其中的参数进行酌情修改.
具体的使用方法, 建立一个具有root权限的用户, 把它的.bashrc进行替换.,, 就能使用那个用户名登陆和建立帐号了.当然,脚本是无法中断的, 所以,不用担心系统的安全问题. |
|