OS系统检查,输出html

#!/bin/bash
# filenam: os_check.sh
# Usage: sh os_check.sh
export routeprefix=$(route -n | egrep -iv "Gateway|routing" | awk '{print $2}' | grep -v "0\.0\.0\.0" | awk -F"." '{print $1"."$2"."$3}' | tail -1)
export ipaddress=$(ip a | grep -w inet | grep $routeprefix | grep -Eiv "secondary|virbr|docker|dynamic|:|127.0.0.1|192.168.1\." | awk -F " +|/" '{ print $3}')
file_output=/tmp/OS_Check_$(date +'%Y%m%d').html
tmp_summary=/tmp/tmp_summary.txt
>$tmp_summary
td_str=''
th_str=''
create_html_css() {
   
    echo -e "<html>
<head>
<title>${ipaddress} OS Check Report</title>
<style type=\"text/css\">
    body        {font:14px Courier New,Helvetica,sansserif; color:black; background:White;}
    table,tr,td {font:14px Courier New,Helvetica,sansserif; color:Black; background:#FFFFCC; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;}
    th          {font:bold 14px Courier New,Helvetica,sansserif; color:White; background:#0099FF; padding:0px 0px 0px 0px;}
    h1          {font:bold 14pt Courier New,Helvetica,sansserif; color:Black; padding:0px 0px 0px 0px;}
</style>
</head>
<body>"
}
create_html_head() {
   
    # echo -e "<h1>$1</h1>"
    echo -e "<br>\n<br>\n<a name=\"$1\"></a>\n<br>\n<font size=+2 face=\"Arial,Helvetica,Geneva,sans-serif\" color=\"#336699\"><b>$1</b></font><hr align=\"left\" width=\"500\">"
}
create_table_head1() {
   
    echo -e "<table width=\"90%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0px\" style=\"border-collapse:collapse\">"
}
create_table_head2() {
   
    echo -e "<table width=\"90%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0px\" style=\"border-collapse:collapse\">"
}
create_th() {
   
    th_str=$(echo $1 | awk 'BEGIN{FS="|"}''{
    i=1; while(i<=NF) {
    print "<th>"$i"</th>";i++}}')
}
create_td() {
   
    td_str=$(echo $1 | awk 'BEGIN{FS="|"}''{
    i=1; while(i<=NF) {
    print "<td><div class=\"content\"><pre>"$i"</pre></div></td>";i++}}')
}
create_td1() {
   
    td_str=$(echo $1 | awk 'BEGIN{FS="|"}''{
    i=1; while(i<=NF) {
    print "<td><div class=\"content\"><pre>"$i"</pre></div></td>";i++}}')
}
create_tr_th() {
   
    create_th "$1"
    echo -e "<tr>
$th_str
</tr>" >>$file_output
}
create_tr_th2() {
   
    create_th "$1"
    echo -e "<tr>
$th_str
</tr>"
}
create_tr_td() {
   
    create_td "$1"
    echo -e "<tr>
$td_str
</tr>" >>$file_output
}
create_tr_td2() {
   
    echo -e "<tr><td><div class=\"content\"><pre style=\"font-family:Courier New; word-wrap: break-word; white-space: pre-wrap; white-space: -moz-pre-wrap\" >
$1
</pre></td></tr>" >>$file_output
}
create_tr_summary() {
   
    echo -e "<tr><th align=\"center\" valign=\"middle\" width=\"10%\">$1</th><td valign=\"middle\" width=\"40%\"><div class=\"content\"><pre style=\"font-family:Courier New; word-wrap: break-word; white-space: pre-wrap; white-space: -moz-pre-wrap\">$2</pre></td><td align=\"center\" valign=\"middle\" width=\"3%\">$3</td><td valign=\"middle\" width=\"35%\"><div class=\"content\"><pre style=\"font-family:Courier New; word-wrap: break-word; white-space: pre-wrap; white-space: -moz-pre-wrap\">$4</pre></td></tr>" >>$tmp_summary
}
create_tr_base() {
   
    echo -e "<tr><th align=\"right\" valign=\"middle\" width=\"20%\">$1</th><td width=\"70%\"><tt>$2</tt></td></tr>" >>$file_output
}
create_table_end() {
   
    echo -e "</table>"
}
create_html_end() {
   
    echo -e "<br>\n<br>\n<br>
<hr align='left' width='30%'>
<b><font color='red'> Edited by IT/MIS/SDA/DBA </font></b>
<br>
<b><font color='blue'> 芯恩(青岛)集成电路有限公司 </font></b>
<br>
<b><font color='blue'> SiEn (QingDao) Integration Corporation </font></b>
<br>\n<br>
</body></html>"
}
create_index() {
   
cat >>$file_output<<create_idx
<br>
<a name="目录"></a>
<br>
<center><font size="+2" face="Arial,Helvetica,Geneva,sans-serif" color="#336699"><b>目录</b></font><hr align="center" width="20%"></center>
<br>
<table width="80%" align="center" border="1" style="margin: auto">
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#巡检常规问题汇总"><font size=+0.5 color="blue"><b>巡检常规问题汇总</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#基本信息"><font size=+0.5 color="blue"><b>基本信息</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#磁盘空间使用信息"><font size=+0.5 color="blue"><b>磁盘空间使用信息</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#Inode空间使用信息"><font size=+0.5 color="blue"><b>Inode空间使用信息</a></td>
  </tr>
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#CPU\内存 Top10"><font size=+0.5 color="blue"><b>CPU\内存 Top10</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#vmstat 检查"><font size=+0.5 color="blue"><b>vmstat 检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#自启动检查"><font size=+0.5 color="blue"><b>自启动检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#crontab 计划任务检查"><font size=+0.5 color="blue"><b>crontab 计划任务检查</a></td>
  </tr>
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#登录检查"><font size=+0.5 color="blue"><b>登录检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#用户检查"><font size=+0.5 color="blue"><b>用户检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#密码检查"><font size=+0.5 color="blue"><b>密码检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#sudo 权限检查"><font size=+0.5 color="blue"><b>sudo 权限检查</a></td>
  </tr>
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#网络配置检查"><font size=+0.5 color="blue"><b>网络配置检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#hosts 文件检查"><font size=+0.5 color="blue"><b>hosts 文件检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#系统参数检查"><font size=+0.5 color="blue"><b>系统参数检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#透明大页(THP)、大页(HugePage)、OS层面NUMA检查"><font size=+0.5 color="blue"><b>透明大页(THP)、大页(HugePage)检查</a></td>
  </tr>
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#防火墙检查"><font size=+0.5 color="blue"><b>防火墙检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#时钟同步检查"><font size=+0.5 color="blue"><b>时钟同步检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#SSH 检查"><font size=+0.5 color="blue"><b>SSH 检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#检查运行的服务"><font size=+0.5 color="blue"><b>检查运行的服务</a></td>
  </tr>
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#zeroconf路由、avahi应用及虚拟网卡禁用情况检查"><font size=+0.5 color="blue"><b>zeroconf路由、avahi应用检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#syslog 检查"><font size=+0.5 color="blue"><b>syslog 检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#"><font size=+0.5 color="blue"><b></a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#"><font size=+0.5 color="blue"><b></a></td>
  </tr>
Oracle_logs
  <tr>
  <td nowrap align="center" width="20%"><a class="link" href="#message Error 日志检查"><font size=+0.5 color="blue"><b>message Error 日志检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#secure 认证失败检查"><font size=+0.5 color="blue"><b>secure 认证失败检查</a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#"><font size=+0.5 color="blue"><b></a></td>
  <td nowrap align="center" width="20%"><a class="link" href="#"><font size=+0.5 color="blue"><b></a></td>
  </tr>
  </table>
<br>
create_idx
}

# 计算过去多久
getHowLongAgo() {
   
    # 计算一个时间戳离现在有多久了
    datetime="$*"
    [ -z "$datetime" ] && echo "错误的参数:getHowLongAgo() $*"
    Timestamp=$(date +%s -d "$datetime") #转化为时间戳
    Now_Timestamp=$(date +%s)
    Difference_Timestamp=$(($Now_Timestamp - $Timestamp))
    days=0
    hours=0
    minutes=0
    sec_in_day=$((60 * 60 * 24))
    sec_in_hour=$((60 * 60))
    sec_in_minute=60
    while (($(($Difference_Timestamp - $sec_in_day)) > 1)); do
        let Difference_Timestamp=Difference_Timestamp-sec_in_day
        let days++
    done
    while (($(($Difference_Timestamp - $sec_in_hour)) > 1)); do
        let Difference_Timestamp=Difference_Timestamp-sec_in_hour
        let hours++
    done
    echo "$days$hours 小时"
}

machine_fac=$(dmidecode -s system-manufacturer)
machine_name=$(dmidecode -s system-product-name)
machine_sn=$(dmidecode -s system-serial-number)
machine_uuid=$(dmidecode -s system-uuid)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值