Loops 如何使该脚本循环X次?
我尝试在GroupAddCoffee下循环5次,每次创建5个新用户。获取这些变量并填写其他命令。完成所有操作后,重新为新用户启动。我上下搜索了一遍,似乎找不出答案。以下是脚本:Loops 如何使该脚本循环X次?,loops,scripting,Loops,Scripting,我尝试在GroupAddCoffee下循环5次,每次创建5个新用户。获取这些变量并填写其他命令。完成所有操作后,重新为新用户启动。我上下搜索了一遍,似乎找不出答案。以下是脚本: #!/bin/bash #Script for adding users and groups if [ $(getent group Coffee) ]; then echo else sudo groupadd Coffee fi
#!/bin/bash
#Script for adding users and groups
if [ $(getent group Coffee) ]; then
echo
else
sudo groupadd Coffee
fi
read -p "What is the new user's login ID? " username
read -s -p "What is the user's password? " password
echo
read -p "What is the new user's full name? " fullname
read -p "What is the new user's initial group? " intgroup
read -p "What is the new user's additional group? " addgroup
if [ $(getent group $intgroup) ]; then
echo
else
sudo groupadd $intgroup
fi
if [ $(getent group $addgroup) ]; then
echo
else
sudo groupadd $addgroup
fi
sudo useradd -m -G Coffee,$intgroup,$addgroup $username
if [ -z $password ]
then
echo -e "newpass\nnewpass" | sudo passwd $username
else
echo -e "$password\n$password" | sudo passwd $username
fi
<pre>
#!/bin/bash
sudo groupadd Coffee
# adds group Coffee to system
COUNTER=0
while [ $COUNTER -lt 5 ]; do
echo The counter is $COUNTER
echo
read -p "What is the new user's login ID? " username
read -s -p "What is the user's password? " password
echo
read -p "What is the new user's full name? " fullname
read -p "What is the new user's initial group? " intgroup
read -p "What is the new user's additional group? " addgroup
#prompts for variables
if [ $(getent group $intgroup) ]; then
echo
else
sudo groupadd $intgroup
fi
#checks to see if specified group is on the system
if [ $(getent group $addgroup) ]; then
echo
else
sudo groupadd $addgroup
fi
#checks to see if specified group is on the system
sudo useradd -m -G Coffee,$intgroup,$addgroup $username
#creates home directory and adds user into groups
if [ -z $password ]
then
echo -e "newpass\nnewpass" | sudo passwd $username
else
echo -e "$password\n$password" | sudo passwd $username
fi
#changes password or gives default one
let COUNTER=COUNTER+1
done
echo
<code>
我知道我可能不得不重新调整,但我希望这是一个简单的东西,我可以添加到修复它 这是我得到帮助的解决方案