批量创建10个用户stu01-stu10
1.批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell循环(例如:for,while等),只能用命令及管道实现。
##方法1:
[root@server tmp]# echo stu{01..10}|tr " " "\n"|sed -r 's#(.*)#useradd \1 ; pass=$((RANDOM+10000000)); echo "$pass"|passwd --stdin \1; echo -e "\1 \t `echo "$pass"`">>/tmp/oldboy.log#g'|bash
useradd: user 'stu01' already exists
Changing password for user stu01.
passwd: all authentication tokens updated successfully.
useradd: user 'stu02' already exists
Changing password for user stu02.
passwd: all authentication tokens updated successfully.
useradd: user 'stu03' already exists
Changing password for user stu03.
passwd: all authentication tokens updated successfully.
useradd: user 'stu04' already exists
Changing password for user stu04.
passwd: all authentication tokens updated successfully.
useradd: user 'stu05' already exists
Changing password for user stu05.
passwd: all authentication tokens updated successfully.
useradd: user 'stu06' already exists
Changing password for user stu06.
passwd: all authentication tokens updated successfully.
useradd: user 'stu07' already exists
Changing password for user stu07.
passwd: all authentication tokens updated successfully.
useradd: user 'stu08' already exists
Changing password for user stu08.
passwd: all authentication tokens updated successfully.
useradd: user 'stu09' already exists
Changing password for user stu09.
passwd: all authentication tokens updated successfully.
useradd: user 'stu10' already exists
Changing password for user stu10.
passwd: all authentication tokens updated successfully.
上述命令实际就是再拼N条下面的命令的组合,举一条命令stu01用户的过程拆解如下:
useradd stu01 ;
pass=$((RANDOM+10000000));
echo "$pass"|passwd --stdin stu01;
echo -e "stu01 `echo "$pass"`">>/tmp/oldboy.log
特别说明:如果用shell循环结构会更简单,之所以限制使用循环的目的是锻炼学生的基础命令运用
能力,学到现在还没学到SHELL循环课程呢
##方法2:
[root@server tmp]# echo stu{11..12}|xargs -n1 useradd ;echo stu{11..12}:`cat /dev/urandom|tr -dc 0-9|fold -w8|head -1`|xargs -n1|tee -a pass.txt|chpasswd
##方法3:
[root@server tmp]# echo stu{21..30} | tr ' ' '\n' | sed -e 's/^/useradd /' -e 's/\(stu[0-9]\{2\}\)$/\1 \&\& echo "\1:`echo $[$RANDOM**3] | cut -c1-8`" | tee -a userInfo.txt | cut -d: -f2 | passwd --stdin \1/' | bash
Changing password for user stu21.
passwd: all authentication tokens updated successfully.
Changing password for user stu22.
passwd: all authentication tokens updated successfully.
Changing password for user stu23.
passwd: all authentication tokens updated successfully.
Changing password for user stu24.
passwd: all authentication tokens updated successfully.
Changing password for user stu25.
passwd: all authentication tokens updated successfully.
Changing password for user stu26.
passwd: all authentication tokens updated successfully.
Changing password for user stu27.
passwd: all authentication tokens updated successfully.
Changing password for user stu28.
passwd: all authentication tokens updated successfully.
Changing password for user stu29.
passwd: all authentication tokens updated successfully.
Changing password for user stu30.
passwd: all authentication tokens updated successfully.
功能: 创建10个用户 分别是 stu21-stu30 其密码是用随机数变量RANDOM生成,均保存至 userInfo.txt中,格式: username:passwd 这个写的不算好 如果有更好的一定要分享哦! 上面的随机数 我之前是用日期生成的,是不对的,因为有可能会有重复现象,所以我后来干脆用RANDOM**3取其前8位,可确保唯一性
##方法4:
[root@server tmp]# echo stu{01..10} |tr ' ' '\n'|sed -rn 's@^(.*)$@useradd \1 ; echo $RANDOM|md5sum|cut -c 1-8 >/data/\1;cat /data/\1|passwd --stdin \1@gp'|bash
useradd: user 'stu01' already exists
Changing password for user stu01.
passwd: all authentication tokens updated successfully.
useradd: user 'stu02' already exists
Changing password for user stu02.
passwd: all authentication tokens updated successfully.
useradd: user 'stu03' already exists
Changing password for user stu03.
passwd: all authentication tokens updated successfully.
useradd: user 'stu04' already exists
Changing password for user stu04.
passwd: all authentication tokens updated successfully.
useradd: user 'stu05' already exists
Changing password for user stu05.
passwd: all authentication tokens updated successfully.
useradd: user 'stu06' already exists
Changing password for user stu06.
passwd: all authentication tokens updated successfully.
useradd: user 'stu07' already exists
Changing password for user stu07.
passwd: all authentication tokens updated successfully.
useradd: user 'stu08' already exists
Changing password for user stu08.
passwd: all authentication tokens updated successfully.
useradd: user 'stu09' already exists
Changing password for user stu09.
passwd: all authentication tokens updated successfully.
useradd: user 'stu10' already exists
Changing password for user stu10.
passwd: all authentication tokens updated successfully.
批量创建10个用户stu01-stu10的更多相关文章
- 运维派 企业面试题4&5 创建10个 用户 ; ping探测主机是否在线
		
Linux运维必会的实战编程笔试题(19题) 企业面试题4: 批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串). #!/bin/bash # ;i<=; ...
 - Linux shell脚本 批量创建多个用户
		
Linux shell脚本 批量创建多个用户 #!/bin/bash groupadd charlesgroup for username in charles1 charles2 charles3 ...
 - shell脚本,批量创建10个系统帐号并设置密码为随机8位字符串。
		
[root@localhost wyb]# cat user10.sh #!/bin/bash #批量创建10个系统帐号wangyb01-wangyb10并设置密码(密码为随机8位字符串). > ...
 - shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。
		
[root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个htm ...
 - linux批量添加10个用户并将其随机密码和用户名写入文件
		
需求: 批量新建10个测试用户,并且让其密码随机,把用户名和密码写入一个文件,并有创建时间和创建者 #!/usr/bin/python # -*- coding: utf-8 -*- import o ...
 - 实现批量添加10个用户,用户名为user01-10,密码为user后面跟3个随机字符
		
#!/bin/bash ` do user="user$i" password=$( | md5sum | ) useradd user$i echo "$user$pa ...
 - 为Sharepoint 2010 批量创建SharePoint测试用户
		
无意搜到下面一篇文章,http://www.cnblogs.com/lambertqin/archive/2012/04/19/2457372.html,原作者写的太"高大上",可 ...
 - 批量创建10个系统帐号tianda01-tianda10并设置密码
		
#.添加用户 useradd tianda01 #.非交互式给密码 echo "pass"|passwd --stdin tianda #.- 加0思路 ()..} () #随机密 ...
 - (转)linux实战考试题:批量创建用户和密码-看看你会么?
		
老男孩教育第五关实战考试题:批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现. 方法1:[roo ...
 
随机推荐
- Axure原型制作规范
			
一. 名词定义: Sitemap 导航图 Widgets 组件 Master 库 Label 控件名 Interactions 交互动作 Annotations 注释 Location and siz ...
 - WEB 基础知识(一)
			
1. 系统架构 1.1 B/S系统架构 1.2 C/S系统架构 1.3 对比与区别 1.3.1 概述 C/S结构,即Client/Server(客户机/服务器)结构,是大家熟知的软件系统体系结构,通过 ...
 - SQL Server 游标运用:鼠标轨迹字符串分割
			
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 游标模板(Cursor Template) 鼠标轨迹字符串分割SQL脚本实现(SQL Code ...
 - 锋利的jQuery--jQuery与DOM对象的互相转换,DOM的三种操作(读书笔记一)
			
1.jQuery对象就是通过jQuery包装DOM对象后产生的对象. 2.jQuery对象和DOM对象的相互转换. 良好的书写风格: var $input=$("input" ...
 - 你可能不知道的陷阱, IEnumerable接口
			
1. IEnumerable 与 IEnumerator IEnumerable枚举器接口的重要性,说一万句话都不过分.几乎所有集合都实现了这个接口,Linq的核心也依赖于这个万能的接口.C语言的 ...
 - [C#] Linq To Objects - 如何操作文件目录
			
Linq To Objects - 如何操作文件目录 开篇语: 上次发布的 <LINQ:进阶 - LINQ 标准查询操作概述> 社会反响不错,但自己却始终觉得缺点什么!“纸上得来终觉浅,绝 ...
 - 杂谈:用 Sublime Text 2 写 ActionScript3
			
Sublime Text这是程序员最喜爱的编辑器,说说在win7下使用Sublime Text来编写as文件以及编译与运行swf. 准备工作 1.Sublime Text 2 2.Java 的JDK( ...
 - [精品书单] C#/.NET 学习之路——从入门到放弃
			
C#/.NET 学习之路--从入门到放弃 此系列只包含 C#/CLR 学习,不包含应用框架(ASP.NET , WPF , WCF 等)及架构设计学习书籍和资料. C# 入门 <C# 本质论&g ...
 - Unmanaged Exports使用方法
			
Unmanaged Exports,可以利用C#生成非托管的DLL文件. 从https://sites.google.com/site/robertgiesecke/下载UnmanagedExport ...
 - flhs笔试题-回家上机实践
			
这是最近参加的一个公司的笔试题,回家上机写了下代码,希望对有需要的小伙伴有用,简单实现字符串和数组在指定位置的插入: package org.flhs; import com.google.commo ...