shell 脚本案例

1.设计一个shell程序,添加组为class1,然后添加属于这个组的30个用户,用户名为 stuxx,其中xx从01到 30

#!/bin/bash
i=1
groupadd class1
while [ $i -le 30 ]
do
if [ $i -le 9 ];then
USERNAME=stu0${i}
else
USERNAME=stu${i}
fi
useradd $USERNAME
mkdir /home/$USERNAME
chown -R $USERNAME /home/$USERNAME
chgrp -R class1 /home/$USERNAME
i=$(($i+1))
done

2.编写一个shell程序,实现自动删除30个账号的功能,账户名为stu01至stu30

#!/bin/bash
i=1
while [ $i -le 50 ]
do
if [ $i -le 9 ];then
name=stu0$i
else
name=stu$i
fi
userdel -r $name
i=$(($i+1))
done

猜你喜欢

转载自www.cnblogs.com/liuhui-xzz/p/10308199.html