[root@master1-192-168-117-18 ~]# vim users.txt
[root@master1-192-168-117-18 ~]# vim Example.sh
#!/bin/bash
read -p "Enter The Users Password:" PASSWD
for UNAME in cat users.txt
do
id $UNAME &> /dev/null
if [ $? -eq 0 ]
then echo "Already exits"
else useradd $UNAME &> /dev/null
echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null
if [ $? -eq 0 ]
then echo "$UNAME,create success!"
else echo "$UNAME,Create failure!"
fi
fi
done
[root@master1-192-168-117-18 ~]# bash Example.sh
Enter The Users Password:1234
zhangsan,create success!
lisi,create success!
wangmazi,create success!
hanmeimei,create success!
lilei,create success!
bobo,create success!
备注:/dev/null是一个被称作Linux黑洞的文件,把输出信息重定向到这个文件等同于删除数据(类似于没有回收功能的垃圾箱),可以让用户的屏幕窗口保持简洁
[root@master1-192-168-117-18 ~]# vim ChechHosts.sh
#!/bin/bash
HLIST=$(cat ~/ipadds.txt) #$(可执行命令)=·可执行命令·
for IP in $HLIST
do
ping -c 3 -i 0.2 -W $IP &> /dev/null
if [ $? -eq 0 ];then
echo"Host $IP is on-line."
else
echo"Host $IP is off-line."
fi
done
来源:51CTO
作者:就是老十三
链接:https://blog.51cto.com/12400136/2460485