免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1134 | 回复: 1
打印 上一主题 下一主题

[原创]第一次写新建帐号的脚本,大家说说能应用吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-11-20 21:15 |只看该作者 |倒序浏览
上过几次openlab,用tarena的帐号登陆,新建用户。
我现在又需要用一下这样的脚本,不会写,看了两天书,就写下了下面的这个,本机实验可行,不知大家怎么看,所以就贴上来,请给个意见(安全方面, 还有代码的缺陷)。

根据用户登陆时的过程,我联想到了.bashrc, 所以就修改.bashrc如下:


  1. #!/bin/bash
  2. #
  3. #.bashrc (Use to add new user for openlab).
  4. #
  5. # To prevent the quit single for system secrity.
  6. #
  7. trap "" 2

  8. # Modify group, logfile:
  9. #
  10. GROUP="users"
  11. LOGFILE="userlog"

  12. #main script file
  13. # Can modify some infomations follow the "echo"
  14. # eg: welcome infomations or error infomatons.
  15. #
  16. # Welcome infomations
  17. #
  18. clear
  19. echo "-=====================================================================-"
  20. echo "-                  W e l c o m e T o T h e O p e n l a b              -"
  21. echo "-=====================================================================-"
  22. echo
  23. echo "Please follow the steps to create your own account!"

  24. for try in 1 2 3 4 5
  25. do
  26.         echo
  27.         echo -n "Please enter your new own account:"
  28.         read ACC
  29.         ##
  30.         if echo "$ACC" | grep '[^a-z0-9]' > /dev/null
  31.                 then
  32.                         echo  
  33.                         echo "name should be all alphanumeric, '-', '_', '.'."
  34.         elif echo "$ACC" | grep '^[a-z]' > /dev/null
  35.                 then
  36.                 if `adduser "$ACC" -g "$GROUP" -d /"$GROUP"/"$ACC"`
  37.                         then
  38.                         echo
  39.                         echo "Please enter your password, sugessted longer than \"6\" !!!"
  40.                         echo
  41.                         passwd $ACC
  42.                
  43.                         # Sucessfull infomation
  44.                         #
  45.                         echo
  46.                         echo "Congratulations, your own account was created."
  47.                         echo "You should relogin later with your new account."
  48.                
  49.                         # userlog, contains account created in the system               
  50.                         #
  51.                         echo "$ACC" | cat >> "$LOGFILE"
  52.                         # standby 5 seconds
  53.                         #
  54.                         sleep 5
  55.                         exit
  56.                         else :
  57.                 fi
  58.         else
  59.                 echo
  60.                 echo "account must begin with lowercase character."
  61.         fi
  62. done

  63. # Many faild times or too errors to create new account.
  64. #
  65. echo "You are trying too many times."
  66. echo "Please try it next time."
  67. sleep 4
  68. exit
复制代码


我的系统: RH9.0

论坛徽章:
0
2 [报告]
发表于 2003-11-20 22:39 |只看该作者

[原创]第一次写新建帐号的脚本,大家说说能应用吗?

好东东~~~~~~~~~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP