shell练习三
2015-08-28 00:00
441 查看
摘要: shell练习三--添加10个用户user1到user10,但要求只有用户不存在的情况下才能添加
shell练习三--添加10个用户user1到user10,但要求只有用户不存在的情况下才能添加
这个只是测试用的,所以我在添加用户的时候加个参数-M,表示不创建目录了
发现在文件下多了下面的东西
再写个脚本删除他们吧,没有什么用处的用户,只是测试
执行脚本删除了用户
shell练习三--添加10个用户user1到user10,但要求只有用户不存在的情况下才能添加
#!/bin/bash for i in `seq 1 10`; do userdel user$i done [root@localhost shell]# cat 3_adduser.sh #!/bin/bash for i in `seq 1 10` ; do cut -d : -f1 /etc/passwd | grep "user$i" 2>> /tmp/etc.err || useradd -M user$i done
这个只是测试用的,所以我在添加用户的时候加个参数-M,表示不创建目录了
[root@localhost shell]# sh 3_adduser.sh
发现在文件下多了下面的东西
dong:x:500:500:dong-linux:/home/dong:/bin/bash user1:x:501:501::/home/user1:/bin/bash user2:x:502:502::/home/user2:/bin/bash user3:x:503:503::/home/user3:/bin/bash user4:x:504:504::/home/user4:/bin/bash user5:x:505:505::/home/user5:/bin/bash user6:x:506:506::/home/user6:/bin/bash user7:x:507:507::/home/user7:/bin/bash user8:x:508:508::/home/user8:/bin/bash user9:x:509:509::/home/user9:/bin/bash user10:x:510:510::/home/user10:/bin/bash
再写个脚本删除他们吧,没有什么用处的用户,只是测试
#!/bin/bash for i in `seq 1 10`; do userdel user$i done
执行脚本删除了用户
[root@localhost shell]# sh 4_deluser.sh
相关文章推荐
- shell练习四
- linux添加用户切换后显示-bash4.1$的解决办法
- Linux Shell高级技巧
- linux shell 命令常用快捷键
- Linux学习日记--基础命令(7)--bash中的变量,配置文件
- linux shell bash 内置变量参考
- Windows中SSH Secure Shell Client 的使用方法
- linux shell——小试牛刀
- shell 语句的应用
- WARN No appenders could be found for logger (org.apache.hadoop.util.Shell).
- 使用bash将csv文件数据读写到MySQL数据库的脚本之一
- 常用shell脚本命令
- 使用bash将csv文件数据读写到MySQL数据库的脚本之一
- 命令__shell数字-字符串比较
- 命令__shell变量$#,$@,$0,$1,$2的含义解释
- HBase 常用Shell命令
- HBase 常用Shell命令
- Linux 解决 bash ./ 没有那个文件或目录 的方法
- linux shell “(())” 双括号运算符使用
- 用xshell5连接vmware10+centos6.7时报Could not connect to '192.168.54.100' (port 22): Connection failed的解法