操作系统信息收集脚本

Shell命令
1081
linux
linux 举报
2020-06-02
#! /bin/sh

# 使用说明: ./stdb_info.sh 数据库名 结果输出文件名
# 如果不指定参数则在当前目录下生成默认结果文件,如果指定的参数不带路径仅文件名,也是在当前目录下生成结果
# 默认输出文件名 STDB_库名_年月日时分秒
# 如果没有指定数据库名,则使用默认数据库名OSRDB

DB_AGENT_NAME=oscaragentd

tar_file_cnt=6
elog_file_cnt=5

if [ -n "$1" ]
then
  DB_NAME=$1
else
  DB_NAME=OSRDB
fi

if [ -n "$2" ]
then
  st_info_file=$2
else
  st_info_file=./STDB_${DB_NAME}_`date +%Y%m%d%H%m%S`
fi

source /etc/profile

st_database_info()
{
  echo -e "\n\n###################AGENT 服务: ###################"
  service $DB_AGENT_NAME status
  srv_status=$?
  if [ $srv_status -eq 1 ]
  then
    if [ ! -f "/etc/init.d/${DB_AGENT_NAME}" ]
    then
      $SZ_OSCAR_HOME/bin/oscaragent -i

      service $DB_AGENT_NAME start
    fi

    if [ `ps -ef | grep $DB_AGENT_NAME | grep -v "grep" | grep -w -i $DB_AGENT_NAME | grep -v "grep" | wc -l` -eq 0 ]
    then
      service $DB_AGENT_NAME start
    fi
  fi
}

#当elogfile文件数多于五个的时候开始压缩,保留最近五个压缩包
st_elog_files_tar()
{
  local pre_dir=$SZ_OSCAR_HOME/log/$DB_NAME

  cd $pre_dir

  tar_file_list=`ls -tr $pre_dir | grep elog.*.txt | head -n $elog_file_cnt` && \
    flag=`ls -tr $pre_dir | grep elog.*.txt | wc -l` || exit

  if [ $flag -gt $elog_file_cnt ] ; then
   tar -czvf elog_`date +%Y%m%d%H%m%S`.tar.gz $tar_file_list
   rm -f $tar_file_list
  fi

  tar_file_del_list=`ls -t $pre_dir | grep elog.*tar.gz | tail -n +$tar_file_cnt`
  rm -f $tar_file_del_list
}

main_call()
{
  echo -e "###################数据库系统信息收集开始时间###################"
  date

  if [ -z "$SZ_OSCAR_HOME" ]
  then
    :
  else
    echo -e "\n\n###################数据库服务: ###################"
    service oscardb_${DB_NAME}d status
    srv_status=$?
    if [ $srv_status -eq 1 ]
    then
      if [ ! -f "/etc/init.d/oscardb_${DB_NAME}d" ]
      then
        $SZ_OSCAR_HOME/bin/oscar -o install -d ${DB_NAME}
      fi
    fi

    if [ `ps -ef | grep oscar | grep -v grep | grep -w -i $DB_NAME | grep -v "grep" | wc -l` -eq 0 ]
    then
      service oscardb_${DB_NAME}d start
    fi

    if [ `ps -ef | grep oscar | grep -v grep | grep -w -i ${DB_NAME} | grep -w ${SZ_OSCAR_HOME} | wc -l` -eq 0 ]
    then
      if [ `ps -ef | grep oscar | grep -v grep | grep -w -i ${DB_NAME} | grep -v "grep" | wc -l` -eq 1 ]
      then
        echo -e "系统环境变量SZ_OSCAR_HOME=${SZ_OSCAR_HOME}对应的数据库可能与当前启动数据库环境变量不一致"
      else
        echo -e "数据库${DB_NAME}未启动(启动异常)或者数据库${DB_NAME}不存在!"
      fi
    else
      echo -e "系统环境变量SZ_OSCAR_HOME=$SZ_OSCAR_HOME,对应数据库版本信息: `$SZ_OSCAR_HOME/bin/oscar --version`"
      st_database_info

      st_elog_files_tar >/dev/null 2>&1
    fi
  fi

  echo -e "\n\n###################数据库系统信息收集结束时间###################"
  date
}

main_call > $st_info_file 2>&1


倒序看帖 只看楼主
热点关注
postfix下过滤垃圾邮件的有效方法
shell脚本每行后面多了一个^M的原因和解决办法
定时检测服务,检测down掉后重启。系统检测到DMSERVER运行正常
挂载磁盘的时候遇到一个问题,挂载完磁盘之后重启服务器挂载的盘丢失了.
中标麒麟系统Your trial is EXPIRED and no VALID licens
termux 开启ssh并用用户名和密码登陆
组成共享库的目标文件和一般的目标文件有所不同,在编译时要加-fPIC和-share选项,例如:
gcc指定链接库路径后还是找不到库文件
./configure -build,-host,-target设置
关于Linux系统中configure中build,target,host中的若干问题
不用单独编译gmp、mpfr和mpc三个包,放在gcc源码下面一起编译
安装最新版本的GCC编译器(./configure执行编译报错 C++ compiler too old)
在后台用进程名运行bash脚本
shell参数判断
postfix过滤规则的几个关键规则