批量创建用户
useradd(){
pw_txt=`mktemp pw.XXXXX`
for i in `seq -s ' ' -w 1 20`
do
useradd user$i
done
cat /dev/urandom | strings -8 | egrep "^[a-zA-Z0-9]{8}$" | head -20 >$pw_txt
for i in `seq -s ' ' -w 1 20`
do
pw=`head -n $i $pw_txt | tail -1`
echo $pw | passwd --stdin user$i
echo -e "user$i\t\t$pw" >> user_add.txt
done
clear
echo "用户创建成功,密码文件时:user_add.txt"
cat user_add.txt
}
useradd
检查服务是否在线
for((i=1;i<4;i++))
do
if ping -c 1 $1 &>/dev/null;then
export count$i=1
else
export count$i=0
fi
sleep 1
done
if [ $count1 -eq $count2 ] && [ $count2 -eq $count3 ] && [ $count3 -eq 0 ];then
echo "$1 is down !"
else
echo "$1 is up !"
fi
unset count1
unset count2
unset count3
查看服务状态
参数:服务+端口号
function port_status() {
temp_file=`mktemp port_status.XXX`
[ ! -x /usr/bin/telnet ] && echo "telnet: not found command!" && exit 1
( telnet $1 $2 <<EOF
quit
EOF
) &>$temp_file
if egrep "\^]" $temp_file &>/dev/null;then
echo "$1 $2 is open"
else
echo "$1 $2 is close"
fi
rm -f $temp_file
}
port_status $1 $2