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. iOS 开发不可缺少的工具

    1.截屏利器:Snip 强大的滚动截屏功能,你值得拥有! Snip.png 传送门:http://www.snip.qq.com/ 2.Mac上最好的终端模拟器:iTerm2 iTeam.png 传送 ...

  2. Python学习--02输入和输出

    命令行输入 x = input("Please input x:") y = raw_input("Please input x:") 使用input和raw_ ...

  3. WCF学习之旅—HTTP双工模式(二十)

    WCF学习之旅—请求与答复模式和单向模式(十九) 四.HTTP双工模式 双工模式建立在上文所实现的两种模式的基础之上,实现客户端与服务端相互调用:前面介绍的两种方法只是在客户端调用服务端的方法,然后服 ...

  4. 扎克伯格开发的家用AI: Jarvis

    扎克伯格本周二在facebook发布了一篇文章,介绍自己利用个人时间开发的一套在自己家里使用的AI系统,并将它命名为Jarvis,对!就是电影钢铁侠里的AI助手Jarvis. 文章并没有讲细节的技术c ...

  5. My First Android Application Project 第一个安卓应用

    一.前言: 安卓(Android):是一种基于Linux的自由及开放源代码的操作系统,主要用在移动设备上,如手机.平板电脑.其他的设备也有使用安卓操作系统,比如:电视机,游戏机.数码相机等等. 二.具 ...

  6. 从零开始编写自己的C#框架(23)——上传组件使用说明

    文章导航 1.前言 2.上传组件功能说明 3.数据库结构 4.上传配置管理 5.上传组件所使用到的类 6.上传组件调用方法 7.效果演示 8.小结 1.前言 本系列所使用的是上传组件是大神July开发 ...

  7. Android 中关于Fragment嵌套Fragment的问题

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/5802146.html 问题描述: 在项目中Activity A中嵌套Fragment B,Fragment ...

  8. RHEL 本地yum源配置

    1.创建挂载目录 # mkdir -p /media/cdrom   2.挂载对应系统版本的iso光盘镜像文件 # mount -o loop -t iso9660 /opt/rhel-server- ...

  9. Redis分布式集群几点说道

    原文地址:http://www.cnblogs.com/verrion/p/redis_structure_type_selection.html  Redis分布式集群几点说道 Redis数据量日益 ...

  10. 【转】async & await 的前世今生

    async 和 await 出现在C# 5.0之后,给并行编程带来了不少的方便,特别是当在MVC中的Action也变成async之后,有点开始什么都是async的味道了.但是这也给我们编程埋下了一些隐 ...