搜索
您的当前位置:首页正文

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

因篇幅问题不能全部显示,请点此查看更多更全内容

Top