Linux批量添加删除用户
2016-05-15 10:33
330 查看
添加用户
删除用户
这两个程序大同小异,其实可以写在一个文件中,用case判断执行的是添加还是删除
( 写于2016年5月15日,http://blog.csdn.net/bzd_111)
. /etc/init.d/functions #调用系统库 > /root/shell/user.txt #清空文件 >/root/shell/false_user.txt for n in $(seq -w 10) #10个用户名产生 do passwd=`echo $(date +%t%N) $RANDOM |md5sum|cut -c 3-10` #随机产生密码并截取8个 useradd zxc-$n >&/dev/null && user_status=$? #添加用户 echo "$passwd"|passwd --stdin zxc-$n >&/dev/null && pass_status=$? #判断是否执行成功,分别写入TXT文件中 if [ $user_status -eq 0 -a $pass_status -eq 0 ] then action "useradd zxc-$n" /bin/true #调用系统库的方法 echo -e "user:\t zxc-$n passwd: \t $passwd ">>/root/shell/user.txt else action "useradd zxc-$n" /bin/false echo -e "user:\t zxc-$n passwd: \t $passwd ">>/root/shell/false_user.txt fi done
删除用户
#!/bin/bash . /etc/init.d/functions for n in $(seq -w 10) do #echo zxc-$n userdel zxc-$n && del_stastus=$? if [ $del_stastus -eq 0 ] then action "userdel zxc-$n" /bin/true else action "userdel zxc-$n" /bin/false fi done
这两个程序大同小异,其实可以写在一个文件中,用case判断执行的是添加还是删除
#!/bin/bash . /etc/init.d/functions > /root/shell/user.txt >/root/shell/false_user.txt RE=0 case "$1" in add) for n in $(seq -w 10) do passwd=`echo $(date +%t%N) $RANDOM |md5sum|cut -c 3-10` useradd zxc-$n >&/dev/null && user_status=$? echo "$passwd"|passwd --stdin zxc-$n >&/dev/null && pass_status=$? if [ $user_status -eq 0 -a $pass_status -eq 0 ] then action "useradd zxc-$n" /bin/true echo -e "user:\t zxc-$n passwd: \t $passwd ">>/root/shell/user.txt else action "useradd zxc-$n" /bin/false echo -e "user:\t zxc-$n passwd: \t $passwd ">>/root/shell/false_user.txt fi done ;; del) for n in $(seq -w 10) do #echo zxc-$n userdel zxc-$n && del_stastus=$? if [ $del_stastus -eq 0 ] then action "userdel zxc-$n" /bin/true else action "userdel zxc-$n" /bin/false fi done ;; *) echo "Usage:$0 {add|del}" exit ;; esac exit $RE
( 写于2016年5月15日,http://blog.csdn.net/bzd_111)
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍