1.输入用户名和密码,批量创建用户。
[root@server ~]# vim for1.sh #创建文件
read -p "输入账户的前缀:" prefix
read -p "输入用户的账户密码:" passwd
for (( i=1;i<=20;i++ ))
do
user=$prefix$i
if id $user > /dev/null
then
echo "$user账户已存在"
else
useradd $user
if [ $? -eq 0 ]
then
echo "$passwd" | passwd --stdin $user &> /dev/null
else
echo "用户创建失败"
exit
fi
fi
done
2.输入网段,检测在这个网段内的ip是否可以ping成功。
[root@server ~]# vim for2.sh
#!/bin/bash
read -p "输入网段:" ip
for(( i=127;i<135;i++ ))
do
IP="$ip"."$i"
echo "$IP"
if ping -c 2 -w 3 $IP &> /dev/null #-w 3 执行时间3s
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
3.免密钥登录
[root@server ~]# vim for3.sh
#!/bin/bash
read -p "please input your password:" ps
for i in `cat ip.txt`
do
ssh $i "echo "$ps" | passwd --stdin root"
done
[root@server fox]# ssh-keygen -t -rsa #制作公私钥对
[root@server fox]# ssh-copy-id root@192.168.175.132 #上传公钥