叶测试 发布的文章

检测数据库中指定表是否存在指定字段脚本

check_mysql_field_exist.sh

    #!/bin/bash
    
    #---------------------------------------
    # 检测数据库是否存在指定字段 变量1:表名 变量2:字段名
    # 注:数据库名同文件夹名
    # author: SenSen 1050575278
    # date: 2021/10/10
    # 注意:所有脚本需测试后方可使用!!!
    #---------------------------------------
    
    if [ "$1" ] && [ "$2" ]; then
    
      #获取当前时间
      curtime=`date +"%Y/%m/%d %H:%M:%S"`
    
      #所在目录
      dir='/web/oa/'
    
      #连接数据库
      db_con="/usr/local/mysql/bin/mysql -uxxx -pxxx"
    
      #自动获取系统目录文件 仅可包含oa系统文件
      sysDir=`ls /web/oa`
    
      for db in ${sysDir}
          do
              ${db_con} -e "select count(*) from information_schema.columns where table_schema = '${db}' and table_name = '${1}' and column_name = '${2}';" >> /web/shell/check_mysql_field_exist.txt
              echo ${db} " done" >> /web/shell/check_mysql_field_exist.txt
          done
    else
        echo "Error: param is empty"
    fi

批量替换指定文件脚本

rewrite_file.sh

#!/bin/bash

#---------------------------------------
# 替换指定文件
# 注:参数1为新文件路径 参数2为原文件路径
# author: SenSen 1050575278
# date: 2021/10/10
# 注意:所有脚本需测试后方可使用!!!
#---------------------------------------

if [ "$1" ] && [ "$2" ]; then

  #获取当前时间
  curtime=`date +"%Y/%m/%d %H:%M:%S"`

  #所在目录
  dir='/web/oa/'

  #自动获取系统目录文件 仅可包含oa系统文件
  sysDir=`ls /web/oa`

  for f in ${sysDir}
    do
      cp -rf ${1} ${dir}${f}/${2}
      echo ${f} " done"
    done
else
    echo "Error: param is empty"
fi

thinkphp批量启动、停止命令行脚本

task.sh

#!/bin/bash

#---------------------------------------
# 批量启动、停止 task [考虑性能,此接口不再使用]
# author: SenSen 1050575278
# date: 2021/10/07
# 注意:所有脚本需测试后方可使用!!!
#---------------------------------------

#获取当前时间
curtime=`date +"%Y/%m/%d %H:%M:%S"`

#判断是否存在参数,不存在则取消
if [ "$1" == 'start' ] || [ "$1" == 'stop' ]; then
    #所在目录
    dir='/web/oa/'

    #自动获取系统目录文件 仅可包含oa系统文件
    sysDir=`ls /web/oa`

    #排除目录
    excluded=()

    for f in ${sysDir}
        do
            #排除指定目录
            if [[ ${excluded[@]/${f}/} != ${excluded[@]} ]]; then
                continue
            fi
            #进入目录
            cd ${dir}${f}
            #执行对应操作
            #/usr/bin/php think task $1
            sleep 1
            echo "${curtime} ${f} done"
        done

else
    echo "Error: param is empty"
fi

thinkphp6中where与whereOr同时使用

whereOr与where同时使用时,需使用闭包模式,避免sql语句错误。

$user = Db::name('user')->where('uuid', $where['uuid'])->find();
if($user['phone'] && $user['card_id']){
    $map1 = [['phone', '=', $user['phone']]];
    $map2 = [['card_id', '=', $user['card_id']]];
    $model = $model->where(function ($query) use ($map1, $map2) {
        $query->whereOr([$map1, $map2]);
    });
}elseif($user['card_id']){
    $model = $model->where('card_id', $user['card_id']);
}elseif($user['phone']){
    $model = $model->where('phone', $user['phone']);
}else{
    $model = $model->where('id', 0);
}

tar.xz文件解压

XZ压缩最新压缩率之王,不过xz也有一个坏处就是压缩时间比较长。
压缩文件:xz -z file
如果要保留被压缩的文件加上参数 -k ,如果要设置压缩率加入参数 -0 到 -9调节压缩率。如果不设置,默认压缩等级是6。
解压文件:xz -d[k] file.xz

解压tar.xz文件
xz -d xxx.tar.xzxxx.tar.xz 解压成 xxx.tar 然后,再用 tar xvf xxx.tar 来解包。

ThinkPHP6操作oracle数据库

ThinkPHP6操作oracle数据库 常见问题:

  1. 使用navicate连接oracle数据库报错:ORA-28547:connection to server failed, probable Oracle Net admin error
    解决:“工具”-“选项”-“环境”oci环境中,下载并指定oracle对应的oci.dll,重启navicate即可。下载地址:https://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
  2. 必须确保php安装的扩展php_pdo_oci.dll php_oci8.dll同oracle版本对应及对应线程类型。windows版下载地址:https://pecl.php.net/package/oci8/2.2.0/windows 或使用https://windows.php.net/downloads/pecl/releases/oci8/2.2.0/

- 阅读剩余部分 -

脚本批量更新文件(即批量文件覆盖)

upgrade.sh
脚本功能:可对多个系统批量覆盖代码(可排除指定系统)需修改对应的目录变量。将zip升级包放置到指定目录中,通过定时任务完成更新。单次只能升级一个版本,不支持数据库升级,仅为文件覆盖功能。

#!/bin/bash

#---------------------------------------
# 批量更新多文件夹内容 支持排除指定目录
# 注:多系统升级时,为避免文件冲突,建议
# 单次单压缩包更新
# author: SenSen 1050575278
# date: 2021/09/10
# 注意:所有脚本需测试后方可使用!!!
#---------------------------------------

#添加定时任务 10min
# */10 * * * * /www/upgrade/upgrade.sh

#记录日志
log="/web/upgrade/upgrade.log"

#进入升级包所在目录 升级包必须包含version.txt文件
cd /web/upgrade/fix

#判断目录中是否有文件 原则上一次只能存在一个文件,避免多个升级包导致混乱
count=`ls -l|grep '^-'|wc -l`

#获取所有系统 废弃
# source ./wlt_dir.sh

#所在目录
baseDir='/web/oa/'

#自动获取系统目录文件 仅可包含oa系统文件
sysDir=`ls /web/oa`

#排除目录
excluded=()

#测试示例
#sysDir=('wlt_3163')

#获取当前目录下的升级包
fixFile=`ls`

if [ $count -ne 0 ]; then
  for i in ${fixFile}
    do
      #获取当前时间
      curtime=`date +"%Y/%m/%d %H:%M:%S"`

      for f in ${sysDir}
        do
          #排除指定目录
          if [[ ${excluded[@]/${f}/} != ${excluded[@]} ]]; then
            continue
          fi
          echo "系统:${f} 升级文件:${i}">>${log}
          #解压到对应系统目录
          unzip -oq ${i} -d ${baseDir}${f}
          echo "${curtime} ${i} done">>${log}
        done
    done
    #移动升级包
    mv ${i} /web/upgrade/bak;
    echo "${i} upgrade successfully">>$log
else
    echo "upgrade_fix is empty"
fi