056-建立任意用戶組並在任意用戶組內建立用戶

看到這個需求時,第一時間想到的2個關鍵字:用戶組,用戶bash

須要解決的問題code

1.判斷輸入用戶是否爲空input

2.兩數之間怎麼取出中間的數值,用什麼方式?cat ?seq? it

#! /bin/bash

##add a new user group, and let all of new user join in.
##written by zhdya_20171011

read -p "pls input a user's group name, like msxf:" g
read -p "pls input a number which from XX and end of XX, like 01 05, it will create msfinance01 ... msfinance05:" n m

if [ -z $g ] && [ -z $n ] && [ -z $m ]
then
        echo "pls it must input the PARA."
        exit
fi

groupadd $g

echo "already created the usergroup $g"

for i in `seq $n $m`
do
        useradd msfinance$i -g $g
done

echo "already created the user you needs."

該腳本不是我寫的哈, 看完以後,是否是明白了怎麼操做呢? 腳本

相關文章
相關標籤/搜索