本脚本参考网络结构,编写linux巡检脚本模板,大家可根据自身需求填写相关检查信息。 模板脚本如下: ``` shell #!/bin/bash ipaddress=`ip a|grep "global"|awk '{print $2}' |awk -F/ '{print $1}'` file_output=os_check_summary_$ipaddress.html td_str='' th_str='' os_log=/var/log/messages os_run_time=`uptime | awk '{print $3}'` os_name=`hostname` os_time=`date "+%Z %Y-%m-%d %Hh%Mm%Ss"` os_edition=`cat /etc/redhat-release` os_memmory=`grep MemTotal /proc/meminfo | awk '{printf "%0.2f",$2/1024/1024}'` os_product_name=`dmidecode | grep 'Product Name' | head -1 |sed 's/:/\n/g' | sed -n '2p'` os_physical_cpu=`cat /proc/cpuinfo |grep "physical id"|sort |uniq|wc -l` os_logical_cpu=`cat /proc/cpuinfo |grep "processor"|wc -l` create_html_css(){ echo -e " " } create_html_head(){ echo -e "$1" } create_table_head1(){ echo -e "" } create_table_head2(){ echo -e "" } create_td(){ td_str=`echo $1 | awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print ""$i"";i++}}'` } create_th(){ th_str=`echo $1|awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print ""$i"";i++}}'` } create_tr1(){ create_td "$1" echo -e " $td_str " >> $file_output } create_tr2(){ create_th "$1" echo -e " $th_str " >> $file_output } create_tr3(){ echo -e " `cat $1` " >> $file_output } create_table_end(){ echo -e "" } create_html_end(){ echo -e "" } NAME_VAL_LEN=12 name_val () { printf "%+*s | %s\n" "${NAME_VAL_LEN}" "$1" "$2" } os_baseinfo(){ echo "检查时间 | 主机名 | 运行天数 | IP地址 | 版本信息 | 内存(GB) | CPU个数 | 逻辑cpu数 | 服务器型号" >>/tmp/tmpbaseinfo_h1_`date +%y%m%d`.txt echo -e "$os_time | $os_name | $os_run_time | $ipaddress |$os_edition | $os_memmory | $os_physical_cpu | $os_logical_cpu | $os_product_name" >>/tmp/tmpbaseinfo_t1_`date +%y%m%d`.txt } os_df_info(){ echo "磁盘路径 | 大小(GB) |使用大小(GB) | 可用大小(GB) | 使用率(100%) | 挂载点 " >>/tmp/tmpdf_h1_`date +%y%m%d`.txt df -hP | sed '1d' | awk '{print $1,"|",$2,"|",$3,"|",$4,"|",$5,"|",$6}' >> /tmp/tmpdf_t1_`date +%y%m%d`.txt } os_dfi_info(){ echo "磁盘路径 | Inode大小(GB) |Inode使用(GB) | Inode可用(GB) | Inode使用率(100%) | Inode挂载点 " >>/tmp/tmpdfi_h1_`date +%y%m%d`.txt df -hiP | sed '1d' | awk '{print $1,"|",$2,"|",$3,"|",$4,"|",$5,"|",$6}' >> /tmp/tmpdfi_t1_`date +%y%m%d`.txt } os_netinfo(){ echo "IP Info " >>/tmp/tmpnet_h1_`date +%y%m%d`.txt ifconfig -a >>/tmp/tmpnet_t1_`date +%y%m%d`.txt } os_log_error(){ echo "OS Log" >>/tmp/tmplog_h1_`date +%y%m%d`.txt tail -400 $os_log >> /tmp/tmplog_t1_`date +%y%m%d`.txt } create_html(){ rm -rf $file_output touch $file_output create_html_css >> $file_output echo "Linux Inspection report" >> $file_output create_html_head "基础信息" >> $file_output create_table_head1 >> $file_output os_baseinfo while read line do create_tr2 "$line" done < /tmp/tmpbaseinfo_h1_`date +%y%m%d`.txt while read line do create_tr1 "$line" done < /tmp/tmpbaseinfo_t1_`date +%y%m%d`.txt create_table_end >> $file_output create_html_head "磁盘空间使用信息" >> $file_output create_table_head1 >> $file_output os_df_info while read line do create_tr2 "$line" done < /tmp/tmpdf_h1_`date +%y%m%d`.txt while read line do create_tr1 "$line" done < /tmp/tmpdf_t1_`date +%y%m%d`.txt create_table_end >> $file_output create_html_head "Inode空间使用信息" >> $file_output create_table_head1 >> $file_output os_dfi_info while read line do create_tr2 "$line" done < /tmp/tmpdfi_h1_`date +%y%m%d`.txt while read line do create_tr1 "$line" done < /tmp/tmpdfi_t1_`date +%y%m%d`.txt create_table_end >> $file_output create_html_head "网络信息" >> $file_output create_table_head1 >> $file_output os_netinfo while read line do create_tr2 "$line" done < /tmp/tmpnet_h1_`date +%y%m%d`.txt while read line do create_tr1 "$line" done < /tmp/tmpnet_t1_`date +%y%m%d`.txt create_table_end >> $file_output create_html_head "系统日志" >> $file_output create_table_head1 >> $file_output os_log_error while read line do create_tr2 "$line" done < /tmp/tmplog_h1_`date +%y%m%d`.txt while read line do create_tr1 "$line" done < /tmp/tmplog_t1_`date +%y%m%d`.txt create_table_end >> $file_output create_html_end >> $file_output sed -i 's/BORDER=1/width="68%" border="1" bordercolor="#000000" cellspacing="0px" style="border-collapse:collapse"/g' $file_output rm -rf /tmp/tmp*_`date +%y%m%d`.txt } # This script must be executed as root RUID=`id|awk -F\( '{print $1}'|awk -F\= '{print $2}'` if [ ${RUID} != "0" ];then echo"This script must be executed as root" exit 1 fi PLATFORM=`uname` if [ ${PLATFORM} = "HP-UX" ] ; then echo "This script does not support HP-UX platform for the time being" exit 1 elif [ ${PLATFORM} = "SunOS" ] ; then echo "This script does not support SunOS platform for the time being" exit 1 elif [ ${PLATFORM} = "AIX" ] ; then echo "This script does not support AIX platform for the time being" exit 1 elif [ ${PLATFORM} = "Linux" ] ; then echo -e " ########################################################################################### #Only support Linux and default directory is current run directory #root user commond: sh os_check.sh #The document output is in HTML format ########################################################################################### " create_html fi ``` 编辑推荐: 【SCRIPT】Linux巡检脚本,巡检报告html格式03-03 How to Collect Diagnostics for Database Hanging Issues (Doc ID 452358.1)03-03 [20211011]跟踪freespace空间的变化情况.txt03-03 网约车的新出口:集体出行来了?03-03 视频怎么调整播放速度,调快或者调慢,需要怎么做03-03 Oracle:审计清理03-03 [20211012]测试远程监听.txt03-03 [20211012]sqlnet.ora USE_DEDICATED_SERVER=on.txt03-03 下一篇: 返回列表 相关推荐 excel表格怎样在数字前输入0 excel中输入数字时默认会自动将0省略,主要是因为它初始 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格里怎么替换数据 Excel中的替换数据具体该如何进行操作才能顺利把数据 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格里面如何插入圆形 Excel是当今社会最流行用的办公软件之一,Excel可以用于 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格里怎么添加表格数据透视表 在excel表格中,数据透视表能够帮助我们快速分析数据,但 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格中怎么添加线边框 Excel中经常需要使用到带有虚线边框的表格,虚线边框的 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格里怎样设置条件自动排序 在excel中可以使用宏实现随内容改变自动排序,那么具体 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格例怎样导入数据库 excel里面形形色色的功能可以帮助用户进行编辑处理数 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 Excel表格如何设置数据排序 在使用excel统计数据时,都会对表格进行排序,具体该如何 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格里怎么选择性粘贴快捷键 Excel中经常需要使用到选择性粘贴这个功能,选择性粘贴 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格怎么插入分隔符号 Excel中经常需要添加分隔符号,分隔符具体该如何添加呢? 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格怎么设置多行多列数据内容排序 excel可以对多行多列数据进行排序。如何操作?今天,小编 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 Excel表格如何设置行和列相互转换 在Excel应用过程中,您是否遇到过需要把行数据转置成列, 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格连接公式怎么使用 Excel中经常需要用到公式进行链接数据,链接公式具体该 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 excel表格怎样链接到cad中 大家工作中有时候会需要一些EXCEL表格数据,那么大家知 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效 2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用 2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce 更新时间:26-02-10 | 作者: | 已阅读:0次 | 标签:点击阅读 最新软件资讯 网约车的新出口:集体出行来了? 网约车的新出口:集体出行来了? 26-03-03 视频怎么调整播放速度,调快或者调慢,需要怎么做 26-03-03 RAC11g搭建-centos7+openfiler+multipath+udev 26-03-03 ORACLE 11g rac for linux升级到19c后台进程Space Manager:slave idle wait过多 26-03-03 热文推荐 网约车的新出口:集体出行来了? 网约车的新出口:集体出行来了? 26-03-03 视频怎么调整播放速度,调快或者调慢,需要怎么做 视频怎么调整播放速度,调快或者调慢,需要怎么做 26-03-03 RAC11g搭建-centos7+openfiler+multipath+udev RAC11g搭建-centos7+openfiler+multipath+udev 26-03-03 ORACLE 11g rac for linux升级到19c后台进程Space Manager:slave idle wait过多 ORACLE 11g rac for linux升级到19c后台进程Space Manager:slave idle wait过多 26-03-03 荣耀手机反弹的法门 荣耀手机反弹的法门 26-03-03 oracle19c安装 单实例 系统centos7 非cdb oracle19c安装 单实例 系统centos7 非cdb 26-03-03 字节跳动再启音乐梦 字节跳动再启音乐梦 26-03-03 【SQL】Oracle SQL处理的流程 【SQL】Oracle SQL处理的流程 26-03-03 【SQL】Oracle SQL共享池检查 【SQL】Oracle SQL共享池检查 26-03-03 Oracle 21C下载和安装 Oracle 21C下载和安装 26-03-03 天极热推 网约车的新出口:集体出行来了? 查看 视频怎么调整播放速度,调快或者调慢,需要怎么做 查看 RAC11g搭建-centos7+openfiler+multipath+udev 查看 ORACLE 11g rac for linux升级到19c后台进程Space Manager:slave idle wait过多 查看 荣耀手机反弹的法门 查看 oracle19c安装 单实例 系统centos7 非cdb 查看