shell脚本

24 篇文章 0 订阅
4 篇文章 0 订阅
批量创建用户
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值