shell脚本-添加用户(非交互式)
2015-07-18 21:14
671 查看
练习,写一个脚本,完成以下要求:
1)、添加用户前,显示系统目前共有多少个用户;
2)、添加4个用户hadoop, mandriva, openstack, mysql;但要先判断用户是否存在,不存在而后再添加,并且显示添加成功的消息
3)、添加完成后,显示系统上共有多少个用户;
#!/bin/bash
# description: show users and add user
#
echo "This system have users(before):"
cat /etc/passwd |wc -l
if id hadoop &> /dev/null ; then
echo "hadoop exists"
else
useradd hadoop &> /dev/null && echo "create hadoop success!"
fi
if id mandriva &> /dev/null ; then
echo "mandriva exists"
else
useradd mandriva &> /dev/null && echo "create mandriva success!"
fi
if id openstack &> /dev/null ; then
echo "openstack exists"
else
useradd openstack &> /dev/null && echo "create openstack success!"
fi
if id mysql &> /dev/null ; then
echo "mysqli exists"
else
useradd mysql &> /dev/null && echo "create musql success!"
fi
echo "This system have users(after):"
cat /etc/passwd |wc -l
1)、添加用户前,显示系统目前共有多少个用户;
2)、添加4个用户hadoop, mandriva, openstack, mysql;但要先判断用户是否存在,不存在而后再添加,并且显示添加成功的消息
3)、添加完成后,显示系统上共有多少个用户;
#!/bin/bash
# description: show users and add user
#
echo "This system have users(before):"
cat /etc/passwd |wc -l
if id hadoop &> /dev/null ; then
echo "hadoop exists"
else
useradd hadoop &> /dev/null && echo "create hadoop success!"
fi
if id mandriva &> /dev/null ; then
echo "mandriva exists"
else
useradd mandriva &> /dev/null && echo "create mandriva success!"
fi
if id openstack &> /dev/null ; then
echo "openstack exists"
else
useradd openstack &> /dev/null && echo "create openstack success!"
fi
if id mysql &> /dev/null ; then
echo "mysqli exists"
else
useradd mysql &> /dev/null && echo "create musql success!"
fi
echo "This system have users(after):"
cat /etc/passwd |wc -l
相关文章推荐
- Shell中while循环的done 后接一个重定向<
- shell中$0,$?,$!等的特殊用法
- SSH Secure Shell Client用pub key认证登录linux
- shell中获得当前的日期
- Eclipse中的File Explorer 打不开/data目录,通过adb shell出现error错误
- shell的基本使用及vi 编程
- bash之条件测试及if语句
- mac 卸载mysql shell脚本
- Mac下通过shell脚本修改properties文件
- shell脚本:位于第一行的#!
- 通过XShell链接虚拟机的CentOS
- UNIX高级编程之简易版shell
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本
- 转:SWT中的Display 对象和 Shell对象
- shell中的${},##和%%的使用
- linux exec /bin/sh shellcode x86 and x86_64
- hbase shell
- 8则实用的Linux Shell命令
- bash数组
- 使用 shell 脚本对 Linux 系统和进程资源进行监控