1. for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10
[root@Server ~]# vim add_user20.sh
#!/bin/bash
read -p "please input username's prefix:" name_pre
read -p "please input user's passwd:" passwd
account=20
for name in ${name_pre}{01..20}
do
useradd $name &>/dev/null
if [ $? -eq 0 ]
then
echo $passwd | passwd --stdin $name &>/dev/null
else
echo "user $name already exists"
fi
done
echo "created $account users successfully"
[root@Server ~]# sh -n add_user20.sh
[root@Server ~]# sh add_user20.sh
[root@Server ~]# tail -20 /etc/passwd
1. for ping测试子网段的主机
网段由用户输入,例如用户输入192.168.101 ,则ping 192.168.101.125 — 192.101.131
UP: /tmp/host_up.txt
Down: /tmp/host_down.txt
[root@Server ~]# vim ping_ip.sh
#!/bin/bash
read -p "请输入网段:" ip
for((i=125;i<=131;i++))
do
IP="$ip"."$i"
echo "$IP"
if ping -c 2 -w 3 $IP &>/dev/null
then
echo "$IP is up" >> /tmp/host_up.txt
else
echo "$IP is down" >> /tmp/host_down.txt
fi
done
echo "up is:" $(cat /tmp/host_up.txt)
echo "down is:" $(cat /tmp/host_down.txt)
[root@Server ~]# sh -n ping_ip.sh
[root@Server ~]# sh ping_ip.sh