• 我先把脚本粘贴在这吧,方便大家观看,其中也是借鉴了不少其他大神的东西,这个脚本主要是用来监控服务器、用户、日志,还得创建备份,等等等等。最近学的shell比较多,就用这个来练练手了,比较简单,大家凑合看吧。
  • #! /bin/bash
    10 # unset any variable which system may be using
    11
    12 # clear the screen
    13 clear
    14
    15 unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage
    16
    17 while getopts iv name
    18 do
    19 case $name in
    20 i)iopt=1;;
    21 v)vopt=1;;
    22 *)echo "Invalid arg";;
    23 esac
    24 done
    25
    26 if [[ ! -z $iopt ]]
    27 then
    28 {
    29 wd=$(pwd)
    30 basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname
    31 scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname)
    32 su -c "cp $scriptname /usr/bin/monitor" root && echo "Congratulations! Script Installed, now run monitor Command" || echo "Installation failed"
    33 }
    34 fi
    35
    36 if [[ ! -z $vopt ]]
    37 then
    38 {
    39 echo -e "tecmint_monitor version 0.1\nDesigned by Tecmint.com\nReleased Under Apache 2.0 License"
    40 }
    41 fi
    42
    43 if [[ $# -eq 0 ]]
    44 then
    45 {
    46
    47
    48 # Define Variable tecreset
    49 tecreset=$(tput sgr0)
    50
    51 # Check if connected to Internet or not
    52 ping -c 1 google.com &> /dev/null && echo -e '\E[32m'"Internet: $tecreset Connected" || echo -e '\E[32m'"Internet: $tecreset Disconnected"
    53
    54 # Check OS Type
    55 os=$(uname -o)
    56 echo -e '\E[32m'"Operating System Type :" $tecreset $os
    57
    58 # Check OS Release Version and Name
    59 cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osrelease
    60 echo -n -e '\E[32m'"OS Name :" $tecreset && cat /tmp/osrelease | grep -v "VERSION" | cut -f2 -d\"
    61 echo -n -e '\E[32m'"OS Version :" $tecreset && cat /tmp/osrelease | grep -v "NAME" | cut -f2 -d\"
    62
    63 # Check Architecture
    64 architecture=$(uname -m)
    65 echo -e '\E[32m'"Architecture :" $tecreset $architecture
    66
    67 # Check Kernel Release
    68 kernelrelease=$(uname -r)
    69 echo -e '\E[32m'"Kernel Release :" $tecreset $kernelrelease
    70
    71 # Check hostname
    72 echo -e '\E[32m'"Hostname :" $tecreset $HOSTNAME
    73
    74 # Check Internal IP
    75 internalip=$(hostname -I)
    76 echo -e '\E[32m'"Internal IP :" $tecreset $internalip
    77
    78 # Check External IP
    79 externalip=$(curl -s ipecho.net/plain;echo)
    80 echo -e '\E[32m'"External IP : $tecreset "$externalip
    81
    82 # Check DNS
    83 nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
    84 echo -e '\E[32m'"Name Servers :" $tecreset $nameservers
    85
    86 # Check Logged In Users
    87 who>/tmp/who
    88 echo -e '\E[32m'"Logged In users :" $tecreset && cat /tmp/who
    89
    90 # Check RAM and SWAP Usages
    91 free -h | grep -v + > /tmp/ramcache
    92 echo -e '\E[32m'"Ram Usages :" $tecreset
    93 cat /tmp/ramcache | grep -v "Swap"
    94 echo -e '\E[32m'"Swap Usages :" $tecreset
    95 cat /tmp/ramcache | grep -v "Mem"
    96
    97 # Check Disk Usages
    98 df -h| grep 'Filesystem\|/dev/sda*' > /tmp/diskusage
    99 echo -e '\E[32m'"Disk Usages :" $tecreset
    100 cat /tmp/diskusage
    101
    102 # Check Load Average
    103 loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
    104 echo -e '\E[32m'"Load Average :" $tecreset $loadaverage
    105
    106 # Check System Uptime
    107 tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
    108 echo -e '\E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime
    109
    110 # Unset Variables
    111 unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage
    112
    113 # Remove Temporary Files
    114 rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage
    115 }
    116 fi
    117 shift $(($OPTIND -1))
  • 这个脚本可以安装也可以直接运行,看你自己的喜好了。无毒无害,你可以试一试,哈哈哈。
    •   安装命令:./tecmint_monitor.sh -i
    •   执行脚本命令:./tecmint_monitor.sh
    •   之后你就可以在任意的一个地方去执行monitor命令,就是这么简单:
    •   你运行命令就会获得下面这些各种各样和系统相关的信息:
      • 互联网连通性
      • 操作系统类型
      • 操作系统名称
      • 操作系统版本
      • 架构
      • 内核版本
      • 主机名
      • 内部IP
      • 外部IP
      • 域名服务器
      • 已登录用户
      • 内存使用率
      • 交换分区使用率
      • 磁盘使用率
      • 平均负载
      • 系统开机时间
    • 这个是运行效果图:
  •   这个脚本其实还是比较好用的,日常的一些监控系统的活都让它干了,这样我自己就比较轻松了。

监控linux系统的简易脚本的更多相关文章

  1. 监控 Linux 系统的 7 个命令行工具

    监控 Linux 系统的 7 个命令行工具: " 深入 关于Linux最棒的一件事之一是你能深入操作系统,来探索它是如何工作的,并寻找机会来微调性能或诊断问题.这里有一些基本的命令行工具,让 ...

  2. 红帽linux系统开机自启动脚本。

    其实很多东西在最后完成以后会觉得也就那样,有意思的是探究的过程. 前段时间老板要求把一个程序做成linux系统开机自启动脚本的模式. 首先你需要写一个脚本. 我这边建立了一个.sh的脚本,就是用脚本启 ...

  3. shell脚本监控Linux系统性能指标

    2016-11-04 22:41 原作者不详 分类: Linux(7) 在服务器运维过程中,经常需要对服务器的各种资源进行监控, 例如:CPU的负载监控,磁盘的使用率监控,进程数目监控等等,以在系统出 ...

  4. 使用Python监控Linux系统

    一.Python编写的监控工具 一.多功能系统资源统计工具dstat 1.dstat介绍 dstat是一个用Python语言实现的多功能系统资源统计工具,用来取代Linux下的vmstat.iosta ...

  5. 第6章:使用Python监控Linux系统

    1.Python编写的监控工具 1).多功能系统资源统计工具dstat dstat是一个用Python编写的多功能系统资源统计工具,用来取代Linux下的vmstat,iostat,netstat和i ...

  6. linux系统带宽监测脚本

    服务器可能经常遇到服务器出带宽跑满,不知如何查询被哪个进程占用的情况,有一款开源的英文软件iftop功能比较强大可以查询相关信息,可能刚接触linux系统的朋友不太会使用,在此写了一个功能比较简单无需 ...

  7. 使用Prometheus监控Linux系统各项指标

    首先在Linux系统上安装一个探测器node explorer, 下载地址https://prometheus.io/docs/guides/node-exporter/ 这个探测器会定期将linux ...

  8. shell脚本监控Linux系统的登录情况

    一.登录日志记录 vi /etc/profile 在最后面添加一行: echo "`who`" > /var/log/login.log 二.监控日志文件 #!/bin/ba ...

  9. Shell 脚本来自动监控 Linux 系统的内存

    # vim /scripts/swap-warning.sh #!/bin/bash #提取本服务器的IP地址信息 IP=`ifconfig eth0 | grep "inet addr&q ...

随机推荐

  1. wordpress 自定义删除后台管理菜单

    <?php /* //wordpress共有5种角色:administrator(管理员) editor(编辑) author(作者) contributor(投稿者) subscriber(订 ...

  2. NET持续集成与自动化部署

    https://www.cnblogs.com/hunternet/p/9590287.html 相信每一位程序员都经历过深夜加班上线的痛苦!而作为一个加班上线如家常便饭的码农,更是深感其痛.由于我们 ...

  3. Mayor's posters (线段树加离散化)

    个人心得:线段树也有了一定的掌握,线段树对于区间问题的高效性还是挺好的,不过当区间过大时就需要离散化了,一直不了解离散化是什么鬼,后面去看了下 离散化,把无限空间中有限的个体映射到有限的空间中去,以此 ...

  4. 【转】Cron表达式简介

    Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每一个域代表一个含义,Cron有如下两种语法格式: Seconds Minutes Hours DayofMonth Month ...

  5. Oracle 12C 新特性之 db默认字符集AL32UTF8、PDB支持不同字符集

    一. db默认字符集AL32UTF8Specify the database character set when you create the database. Starting from Ora ...

  6. MQTT协议通俗讲解

    参考 Reference v3.1.1 英文原版 中文翻译版 其他资源 网站 MQTT官方主页 Eclipse Paho 项目主页 测试工具 MQTT Spy(基于JDK) Chrome插件 MQTT ...

  7. 获得Oracke中刚插入的ID ---> GetInsertedID()

    (1)首先 需要创建序列: CREATE SEQUENCE SE_TD_POWER MINVALUE 1 NOMAXVALUE START WITH 1 INCREMENT BY 1 NOCYCLE ...

  8. php大型网站如何提高性能和并发访问

    一.大型网站性能提高策略: 大型网站,比如门户网站,在面对大量用户访问.高并发请求方面,基本的解决方案集中在这样几个环节:使用高性能的服务器.高性能的数据库.高效率的编程语言.还有高性能的Web容器. ...

  9. Python函数(三)-局部变量

    全局变量 全局变量在函数中能直接访问 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" name = 'John' def te ...

  10. 11-24网页基础--Js框架及学习思路

    第一部分 基本语法: 1.数据类型(字符串.小数.整数.布尔.时间日期)var s="3.14" var n=parsefloat(s) s+=5;var s="abc3 ...