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的更多相关文章

  1. 运维派 企业面试题4&5 创建10个 用户 ; ping探测主机是否在线

    Linux运维必会的实战编程笔试题(19题) 企业面试题4: 批量创建10个系统帐号oldboy01-oldboy10并设置密码(密码为随机8位字符串). #!/bin/bash # ;i<=; ...

  2. Linux shell脚本 批量创建多个用户

    Linux shell脚本 批量创建多个用户 #!/bin/bash groupadd charlesgroup for username in charles1 charles2 charles3 ...

  3. shell脚本,批量创建10个系统帐号并设置密码为随机8位字符串。

    [root@localhost wyb]# cat user10.sh #!/bin/bash #批量创建10个系统帐号wangyb01-wangyb10并设置密码(密码为随机8位字符串). > ...

  4. shell脚本,在指定目录下通过随机小写10个字母加固定字符串oldboy批量创建10个html文件。

    [root@localhost wyb]# cat test10.sh #!/bin/bash #使用for循环在/test10目录下通过随机小写10个字母加固定字符串oldboy批量创建10个htm ...

  5. linux批量添加10个用户并将其随机密码和用户名写入文件

    需求: 批量新建10个测试用户,并且让其密码随机,把用户名和密码写入一个文件,并有创建时间和创建者 #!/usr/bin/python # -*- coding: utf-8 -*- import o ...

  6. 实现批量添加10个用户,用户名为user01-10,密码为user后面跟3个随机字符

    #!/bin/bash ` do user="user$i" password=$( | md5sum | ) useradd user$i echo "$user$pa ...

  7. 为Sharepoint 2010 批量创建SharePoint测试用户

    无意搜到下面一篇文章,http://www.cnblogs.com/lambertqin/archive/2012/04/19/2457372.html,原作者写的太"高大上",可 ...

  8. 批量创建10个系统帐号tianda01-tianda10并设置密码

    #.添加用户 useradd tianda01 #.非交互式给密码 echo "pass"|passwd --stdin tianda #.- 加0思路 ()..} () #随机密 ...

  9. (转)linux实战考试题:批量创建用户和密码-看看你会么?

    老男孩教育第五关实战考试题:批量创建10个用户stu01-stu10,并且设置随机8位密码,要求不能用shell的循环(例如:for,while等),只能用linux命令及管道实现. 方法1:[roo ...

随机推荐

  1. 设计模式之接口隔离原则(ISP)

    一.定义: ISP:Interface Segregation Principle 接口隔离原则表明客户端不应该被强迫实现一些他们不会使用的接口,应该把胖接口中的方法分组,然后用多个接口代替它,每个接 ...

  2. 【CSS3动画】transform对文字及图片的旋转、缩放、倾斜和移动

    前言:之前我有写过CSS3的transform这一这特性,对于它的用法,还不是很透彻,今天补充补充,呵呵 你懂的,小司机准备开车了. a)再提一提transform的四个属性 ①旋转--->ro ...

  3. XSS原理

    跨站脚本攻击(Cross-Site Scripting),是一种网站应用程序的安全漏洞,是代码注入攻击的一种.   XSS的种类:   反射型XSS: 非持久型XSS(需要自行触发,输入-输出).  ...

  4. 火狐浏览器中event不起作用解决办法--记录(一)

    今天遇到了这个问题.IE,谷歌下都没问题,但在FF下却不起作用,很郁闷查了半天,看别人博文写了老长,结果试了要么起作用,但太麻烦,要么不起作用,说了那么多跟没说一样. 其实只要这一句代码就行:e=ar ...

  5. 2. SVM线性分类器

    在一个线性分类器中,可以看到SVM形成的思路,并接触很多SVM的核心概念.用一个二维空间里仅有两类样本的分类问题来举个小例子.如图所示 和是要区分的两个类别,在二维平面中它们的样本如上图所示.中间的直 ...

  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(54)-工作流设计-所有流程监控

    系列目录 先补充一个平面化登陆页面代码,自己更换喜欢的颜色背景 @using Apps.Common; @{ Layout = null; } <!DOCTYPE html> <ht ...

  7. 个人随想:对于一个.Neter来说,如果一直想走技术路线,该怎么走下去

    前言 首先我不是一个合格的.Neter,也许在这里我的技术算是很菜的,不过我也是有想法的人,下面罗列出我的想法和将要实现的技术路线图. 1.学习一门底层语言 比如学习C语言,学习C语言的最终目的我觉得 ...

  8. 前端CSS部分知识整理

    1.如何清除图片下方出现几像素的空白间隙? /*方法1:*/ img{display:block;} 方法2: /*img{vertical-align:top;}*/ 2.如何让文本垂直对齐文本输入 ...

  9. dicom通讯的工作方式及dicom标准简介

    本文主要讲述dicom标准及dicom通讯的工作方式.dicom全称医学数字图像与通讯 其实嘛就两个方面 那就是“存储”跟“通讯”. 文件数据组织方式  网络数据组织方式.文件数据组织方式就是解析静态 ...

  10. 【Java每日一题】20161223

    package Dec2016; public class Ques1223 { public static void main(String[] args){ Integer obj = Integ ...