一、创建、删除、查看用户,随机生成八位数密码

#!/bin/bash
#Author:yanglt
#!/bin/bash
#Author:yanglt
#Blog:https://www.cnblogs.com/yangleitao/
#Time:-- ::
#Version:V1. function wait()
{
echo -n '3秒后继续'
for ((i=;i<;i++))
do
echo -n "...";sleep
done
echo
}
in_check(){
expr $num1 + >/dev/null >&
if [ $? -ne ];then
echo "please input number"
exit
fi
}
empty_check(){
if [ ! $name ];then
echo "The input cannot be empty"
continue
fi
}
while true
do
cat<<EOF
#################################
.create user
.delete user
.query user
.exit
################################
EOF
read -p "Please input num:" num
in_check
case "$num" in
)
read -p "please input name:" name
empty_check
grep -w $name /etc/passwd >/dev/null
if [ $? -eq ];then
echo -e "$name already exist"
exit
else
useradd -s /bin/bash $name
echo -n `mkpasswd -l ` |tee -a ${name}Passwd.txt|passwd --stdin $name
echo -e "$name create successful"
fi
;;
)
read -p "please input delete name:" name
empty_check
grep -w $name /etc/passwd >/dev/null
if [ $? -ne ];then
echo -e "$name is not exist"
exit
else
userdel -r $name
rm -rf ${name}Passwd.txt
echo -e "$name delete successful"
fi
;;
)
read -p "please input need query name:" name
empty_check
grep -w $name /etc/passwd >/dev/null
if [ $? -eq ];then
echo `grep -w $name /etc/passwd`
echo -e `awk '{print "Password:",$0}' ${name}Passwd.txt`
else
echo -e "$name is not exist"
continue
fi
;;
*)
exit
;;
esac
wait
done

二、用户管理改进

[root@localhost ~]# cat UserManger03.sh
#!/bin/bash
#Author:yanglt
#!/bin/bash
#Author:yanglt
#Blog:https://www.cnblogs.com/yangleitao/
#Time:-- ::
#Version:V1.
. /etc/init.d/functions #调用内部函数action function wait()
{
echo -n '2秒后继续'
for ((i=;i<;i++))
do
echo -n "...";sleep
done
echo
}
in_check(){
expr $num1 + >/dev/null >&
if [ $? -ne ];then
echo "please input number"
exit
fi
}
empty_check(){
if [ ! $name ];then
echo "The input cannot be empty"
continue
fi
}
makedir(){
dir=/yanglt/
[ ! -n $dir ]&& mkdir $dir
} action_check(){
if [ $? -eq ];then
action "useradd $name successful" /bin/true
else
action "useradd $name " /bin/false
fi
}
while true
do
cat<<EOF
#################################
.create user
.delete user
.query user
.exit
################################
EOF
read -p "Please input num:" num
in_check
case "$num" in
)
read -p "please input name:" name
empty_check
pass=`mkpasswd -l `
grep -w $name /etc/passwd >/dev/null
if [ $? -eq ];then
echo -e "$name already exist"
exit
else
makedir
useradd -s /bin/bash $name &>/dev/null
echo $pass|passwd --stdin $name &>/dev/null
action_check
echo -e "$name\t$pass" >> /yanglt/Passwd.txt
fi
;;
)
read -p "please input delete name:" name
empty_check
grep -w $name /etc/passwd >/dev/null
if [ $? -ne ];then
echo -e "$name is not exist"
exit
else
userdel -r $name
sed -i "/^$name$/d" /yanglt/Passwd.txt #进一步了解精确匹配,和变量匹配
echo -e "$name delete successful"
fi
;;
)
read -p "please input need query name:" name
empty_check
grep -w $name /etc/passwd >/dev/null #-w 精确匹配
if [ $? -eq ];then
grep -w "$name" /etc/passwd
grep -w "$name" /yanglt/Passwd.txt
else
echo -e "$name is not exist"
continue
fi
;;
*)
exit
;;
esac
wait
done
[root@localhost ~]#

【shell 练习4】编写Shell用户管理脚本(二)的更多相关文章

  1. linux系统用户管理(二)

    5.组命令管理**组账户信息保存在/etc/group和/etc/gshadow两个文件中 /etc/group 组账户信息 [root@localhost ~]# head -2 /etc/grou ...

  2. Identity用户管理入门二(显示用户列表)

    在Controllers中新建AccountController,并在构造方法(函数)中注入SignInManager,UserManager UserManager   用户管理(注册,查找,修改, ...

  3. 【shell 练习3】用户管理脚本(一)

    一.创建十个用户,密码为八位 [root@localhost ~]# cat UserManger02.sh #!/bin/bash . /etc/init.d/functions [ $UID -n ...

  4. PC Server远程管理卡用户管理脚本实现

    1.IPMI工作原理图: 2.脚本实现流程图: 3.适配服务器机型: 4.演示效果: 5.实现代码: #!/usr/bin/env bash # Author : JACK ZHAO # Date : ...

  5. 转自ruby迷: 使用Net::SSH和Net::SCP编写Linux服务器管理脚本

    试了一下perl下安装ssh模块,整了半天linux/window上都装不上,各依赖模块的版本总是匹配不上,后改了一下思路,用ruby吧 Net::SSH和Net::SCP是两个Ruby操作SSH的g ...

  6. linux用户管理(二)

    最简单的加入用户useradd 用户名这样的命令不好,因为会新建一个组为这个用户. 这里提到一个问题,为什么普通用户没有/etc/shadow的写权限却能修改自己的密码呢. 因为 /user/bin/ ...

  7. Linux 用户管理(二)

    一.groupadd --create a new group 创建新用户 -g  --gid GID 二.groupdel --delete a group 三.passwd --update us ...

  8. linux下的用户管理(二)

    创建帐号: 手工创建-> 1.在/etc/passwd中添加一条记录 2.创建用户主目录 3.在用户的家目录下设置默认的配置文件 4.设置用户初始口令 命令创建-> useradd或add ...

  9. 编写shell管理脚本(二)

    8.1  先测试“/etc/vsftpd”.“/etc/hosts”是否为目录,并通过“$?”变量查看返回状态值,据此判断测试结果.[root@localhost ~]# [ -d /etc/vsft ...

随机推荐

  1. mobBUS

    1.今天听陈刚说起modBUS通信协议,这个还是第一次听说,究竟是什么东东,还是上网查查看吧 2.网上有C语言程序. http://blog.163.com/li_g888@126/blog/stat ...

  2. 关于session序列化和session钝化和活化

    在第一次启动服务器后,在session中放入一个对象.在页面可以获得,当重启服务器,但是没有关闭浏览器的情况下刷新页面仍然能够获得这个对象,前提是这个对象必须实现了java.io.Serializab ...

  3. .net core运行环境搭建 linux + windows

    ---------------------------------------linux------------------------------------------------- 一.添加do ...

  4. redis存储数据的时候

    使用redis存储数据的时候,有时候为了查看的方便,通常会有层级或者说是目录, 这时候我们在set的时候,需要将key值使用“:”的符号来区分层级关系,比如:set(“a:b”, “123”),那么在 ...

  5. iOS获取通讯录所有联系人信息

    以下是2种方式: 第一种方法: GetAddressBook.h #import <Foundation/Foundation.h> @interface GetAddressBook : ...

  6. iOS之动态计算文字的高度

    + (CGSize)boundingALLRectWithSize:(NSString *)txt Font:(UIFont *)font Size:(CGSize)size { NSMutableA ...

  7. Java并发包:AtomicBoolean和AtomicReference

      AtomicBoolean AtomicBoolean是一个读和写都是原子性的boolean类型的变量.这里包含高级的原子操作,例如compareAndSet().AtomicBoolean位于J ...

  8. Spring + Mybatis应该如何配置

    ### 1. MYBATIS简介 MYBATIS是持久层框架,大大的简化了持久层开发. 当使用MYBATIS框架时,开发人员不必再编写繁琐的JDBC代码,只需要定义好每个功能对应的抽象方法与需要执行的 ...

  9. Django的MVT的思路

    1.先上两张图片 2.我的理解 view在MVT框架里面,起到的是中间调度的作用. a.在diango里面有个关键性路径的配置 就是在django2.0前的url和在2.0后的path. 为避免一个项 ...

  10. 百度地图定位JSP代码

    附:百度地图API:http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a1b0?qq-pf-to=pcqq.c2c &l ...