zoukankan      html  css  js  c++  java
  • shell 读取文本并访问mysql/redis

    #!/bin/bash
    File="redeemcode.csv"
    #File=$1
    
    database="d_redeem_info"
    
    echo "check redeemcode state begin..."
    
    while read line
    do
    if [ -z "$line" ];then
     echo "is null"
    else
     #rlt=`mysql -D $database -h127.0.0.1 -uroot -proot -e "select * from  t_redeem_code where c_redeem_code = '${line%?}';" `
     rlt=$(mysql -D $database -h127.0.0.1 -uroot -proot -e "select * from  t_redeem_code where c_redeem_code = '${line%?}';" )
    cham=`redis-cli -h 192.168.1.6 -p 6380 hset guild_info:${arr[0]} activity_contribution  ${arr[1]}`
    fi done < ${File} echo "check redeemcode state end..."

    shell传参:$0 为执行的文件名,$n,n代表第几个参数

    读文件:

    while read line
    do
      echo $line
    done < ${File}

    逻辑判断:

    if [ -z "$line" ];then
     echo "is null"
    else
     echo "not null"
    fi

    shell去掉最后一个字符:

    ${line%?}

    接收mysql操作返回值:

    rlt='mysql -h ......'
    rlt=$(mysql -h ......)
  • 相关阅读:
    Fiddler工具抓包
    简单Ant打包
    android中ActionBar的几个属性
    yum安装php7.2
    java 获取计算机内存
    docker apache安装
    docker 安装 openresty
    docker 安装nginx
    docker安装gitlab
    java获取时间格式
  • 原文地址:https://www.cnblogs.com/faithfu/p/9442023.html
Copyright © 2011-2022 走看看