运维笔试Shell编程题
生活随笔
收集整理的這篇文章主要介紹了
运维笔试Shell编程题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、實現批量添加10個用戶,用戶名為user01-10,密碼為user后面跟3個隨機字符;
#!/bin/bash for i in `seq -w 1 10` douser="user$i"password=$(cat /dev/urandom | head -1 | md5sum | head -c 3)useradd user$iecho "$user$password" | passwd --stdin $userecho "$user$password" >> userinfo.txt done說明:
seq -w 1 10? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 產生01,...10等10位數字
cat /dev/urandom | head -1 | md5sum | head -c 3? ? ? # 產生3位隨機字母或數字
useradd user? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 添加用戶命令
echo "$user$password" | passwd --stdin $user? ? ? ? ? ?# 設置密碼
echo "$user$password" >> userinfo.txt? ? ? ? ? ? ? ? ? ? ?# 產生的用戶名和密碼文件放置到userinfo.txt
轉載于:https://www.cnblogs.com/opsprobe/p/11588628.html
總結
以上是生活随笔為你收集整理的运维笔试Shell编程题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 运维笔试Python编程题
- 下一篇: 石川es6课程---1-2、ES6简介