shell脚本中常用的技能

前端之家收集整理的这篇文章主要介绍了shell脚本中常用的技能前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#/bin/bash
threadCount=`cat count`;
topic=`cat topic`
#echo $topic
#访问文件中每行的数据
for redis in $(cat redis.list); do
    echo $redis
    host=`echo $redis | awk -F ":" '{print $1}'`
    port=`echo $redis | awk -F ":" '{print $2}'`
    #echo $host
    #echo $port
    #shell for循环
    #for i in {1..50}; do
    for (( index=0; index<$threadCount; index++ )); do
        queueName=hehe-haha-$topic-2.2.2.223-$index
        queueName2=hehe-haha-$topic-2.2.2.223-$index
        #echo $queueName
        result=`redis-cli -h $host -p $port zcard $queueName`
        #echo $result
        # shell if判断
        if [ "$result" != "0" ]; then
            echo "redis: $redis queue: $queueName length is $result "
            zrangeResult=`redis-cli -h $host -p $port zrange $queueName 0 -1 withscores`
            echo $zrangeResult
            #shell中的字符串按照空格分割存到数组中
            #array=(${zrangeResult})
            # 数组的长度
            #num=${#array[@]}
            #for ((i=0; i<num;)); do
            # value=${array[i]}
            # i=$((i+1))
            # score=${array[i]}
            # i=$((i+1))
            # redis-cli -h $host -p $port zadd $queueName2 $score $value
            #done
        fi
    done
done

猜你在找的Bash相关文章