数据库运行环境

数据库信息收集脚本

#! /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

操作系统信息收集脚本

#! /bin/sh

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

if [ -n "$1" ]
then
  sys_info_file="$1"
else
  sys_info_file=./sys_`date +%Y%m%d%H%m%S`
fi

sys_info()
{
  echo -e "\n###################CPU 信息: ###################"
  cat /proc/cpuinfo

  echo -e "\n\n###################内存、交换内存信息: ###################"
  free | grep -E "Mem|Swap" | awk '{print $1," 内存大小:", $2/1024 "MB ,已用:",$3/1024 "MB" ,"剩余:" $4/1024 "MB"}'

  echo -e "\n\n###################操作系统信息: ###################"
  cat /etc/issue

  echo -e "\n\n###################操作系统位数: ###################"
  getconf LONG_BIT | awk '{print "OS位数:",$1}'

  echo -e "\n\n###################内核信息: ###################"
  uname -a

  echo -e "\n\n###################网卡信息: ###################"
  lspci | grep Ethernet

  echo -e "\n\n###################IP 地址列表: ###################"
  ifconfig | grep -E "eth|addr" | grep -E "eth|Bcast"

  echo -e "\n\n###################磁盘信息: ###################"
  df -hl

  echo -e "\n\n###################防火墙状态: ###################"
  service iptables status
  srv_status=$?
  if [ $srv_status -eq 1 ]
  then
    :
  else
    if [ $srv_status -eq 0 ]
    then
      service iptables stop
    fi
  fi

  echo -e "\n\n###################CPUSPEED 状态: ###################"
  service cpuspeed status
  srv_status=$?
  if [ $srv_status -eq 1 ]
  then
    :
  else
    if [ $srv_status -eq 0 ]
    then
      service cpuspeed stop
    fi
  fi

  echo -e "\n\n###################SSHD 状态: ###################"
  service sshd status
  srv_status=$?
  if [ $srv_status -eq 1 ]
  then
    :
  else
    if [ $srv_status -eq 3 ]
    then
      service sshd start
    fi
  fi

  echo -e "\n\n###################JAVA 虚拟机版本: ###################"
  java -version

  echo -e "\n\n###################GCC 版本: ###################"
  gcc -dumpversion
}

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

  sys_info

  echo -e "\n\n###################操作系统信息收集结束时间###################"
  date
}

main_call > "$sys_info_file" 2>&1