- 论坛徽章:
- 0
|
上过几次openlab,用tarena的帐号登陆,新建用户。
我现在又需要用一下这样的脚本,不会写,看了两天书,就写下了下面的这个,本机实验可行,不知大家怎么看,所以就贴上来,请给个意见(安全方面, 还有代码的缺陷)。
根据用户登陆时的过程,我联想到了.bashrc, 所以就修改.bashrc如下:
- #!/bin/bash
- #
- #.bashrc (Use to add new user for openlab).
- #
- # To prevent the quit single for system secrity.
- #
- trap "" 2
- # Modify group, logfile:
- #
- GROUP="users"
- LOGFILE="userlog"
- #main script file
- # Can modify some infomations follow the "echo"
- # eg: welcome infomations or error infomatons.
- #
- # Welcome infomations
- #
- 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
复制代码
我的系统: RH9.0 |
|