Linux系统监控shell脚本

开源项目

https://github.com/atarallo/TECMINT_MONITOR

#! /bin/bash
# unset any variable which system may be usingunset tecreset os architecture kernelrelease internalip externalip nameserver loadaveragewhile getopts iv name
docase $name ini)iopt=1;;v)vopt=1;;*)echo "Invalid arg";;esac
doneif [[ ! -z $iopt ]]
then
{
wd=$(pwd)
basename "$(test -L "$0" && readlink "$0" || echo "$0")" > /tmp/scriptname
scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname)
su -c "cp $scriptname /usr/bin/monitor" root && echo "Congratulations! Script Installed, now run monitor Command" || echo "Installation failed"
}
fiif [[ ! -z $vopt ]]
then
{
echo -e "tecmint_monitor version 0.1\nDesigned by Tecmint.com\nReleased Under Apache 2.0 License"
}
fiif [[ $# -eq 0 ]]
then
{# Define Variable tecreset
tecreset=$(tput sgr0)# Check if connected to Internet or not
ping -c 1 google.com &> /dev/null && echo -e '\E[32m'"Internet: $tecreset Connected" || echo -e '\E[32m'"Internet: $tecreset Disconnected"# Check OS Type
os=$(uname -o)
echo -e '\E[32m'"Operating System Type :" $tecreset $os# Check OS Release Version and Name
###################################
OS=`uname -s`
REV=`uname -r`
MACH=`uname -m`GetVersionFromFile()
{VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
}if [ "${OS}" = "SunOS" ] ; thenOS=SolarisARCH=`uname -p`OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; thenOSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; thenKERNEL=`uname -r`if [ -f /etc/redhat-release ] ; thenDIST='RedHat'PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`elif [ -f /etc/SuSE-release ] ; thenDIST=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`REV=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`elif [ -f /etc/mandrake-release ] ; thenDIST='Mandrake'PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`elif [ -f /etc/os-release ]; thenDIST=`awk -F "PRETTY_NAME=" '{print $2}' /etc/os-release | tr -d '\n"'`elif [ -f /etc/debian_version ] ; thenDIST="Debian `cat /etc/debian_version`"REV=""fiif ${OSSTR} [ -f /etc/UnitedLinux-release ] ; thenDIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"fiOSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"fi##################################
#cat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osrelease
#echo -n -e '\E[32m'"OS Name :" $tecreset  && cat /tmp/osrelease | grep -v "VERSION" | grep -v CPE_NAME | cut -f2 -d\"
#echo -n -e '\E[32m'"OS Version :" $tecreset && cat /tmp/osrelease | grep -v "NAME" | grep -v CT_VERSION | cut -f2 -d\"
echo -e '\E[32m'"OS Version :" $tecreset $OSSTR 
# Check Architecture
architecture=$(uname -m)
echo -e '\E[32m'"Architecture :" $tecreset $architecture# Check Kernel Release
kernelrelease=$(uname -r)
echo -e '\E[32m'"Kernel Release :" $tecreset $kernelrelease# Check hostname
echo -e '\E[32m'"Hostname :" $tecreset $HOSTNAME# Check Internal IP
internalip=$(hostname -I)
echo -e '\E[32m'"Internal IP :" $tecreset $internalip# Check External IP
externalip=$(curl -s ipecho.net/plain;echo)
echo -e '\E[32m'"External IP : $tecreset "$externalip# Check DNS
nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
echo -e '\E[32m'"Name Servers :" $tecreset $nameservers # Check Logged In Users
who>/tmp/who
echo -e '\E[32m'"Logged In users :" $tecreset && cat /tmp/who # Check RAM and SWAP Usages
free -h | grep -v + > /tmp/ramcache
echo -e '\E[32m'"Ram Usages :" $tecreset
cat /tmp/ramcache | grep -v "Swap"
echo -e '\E[32m'"Swap Usages :" $tecreset
cat /tmp/ramcache | grep -v "Mem"# Check Disk Usages
df -h| grep 'Filesystem\|/dev/sda*' > /tmp/diskusage
echo -e '\E[32m'"Disk Usages :" $tecreset 
cat /tmp/diskusage# Check Load Average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e '\E[32m'"Load Average :" $tecreset $loadaverage# Check System Uptime
tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e '\E[32m'"System Uptime Days/(HH:MM) :" $tecreset $tecuptime# Unset Variables
unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage# Remove Temporary Files
rm /tmp/who /tmp/ramcache /tmp/diskusage
}
fi
shift $(($OPTIND -1))

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/382539.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux ubuntu 软件安装的三种方式

apt-get 自动安装软件,解决依赖关系 sudo apt-get update 更新源 源在 /etc/apt/sources.list 文件中sudo apt-get install softwarename sudo apt-get remove softwarenamedpkg 根据deb安装包来安装软件 dpkg 是“Debian Packager ”的简写 sudo dpkg -i xxx.de…

linux 用户管理以及其他命令

设置用户组 sudo groupadd test 增加test用户组创建用户 选项: -s 指定shell -g 指定组 -d 用户家目录 -m 家目录不在时,自动创建 sudo useradd -s /bin/bash -g test -d /home/newuser -m newuser设置密码 sudo passwd newuser切换用户 su xiaowan…

蒙特卡洛法求圆周率100亿数据

代码 import time import random hits0 pi0 DARTS100000*100000 starttime.perf_counter() for i in range(DARTS):x,yrandom.random(),random.random()distpow(x ** 2y**2,0.5)if dist < 1.0:hits1 pi4*(hits/DARTS) print("圆周率的值是{:.10f}".format(pi)) p…

linux gcc 简单使用记录01

大体编译流程 gcc 参数&#xff1a; I 包含头文件路径 L 包含库文件路径 l 库名 比如libxxx.so 对应着 -lxxx(掐头去尾) O 优化选项 1&#xff0c;3 W 警告 all 显示更多的 c 编译成 .o 文件&#xff08;二进制&#xff09; E 输出到标准输出&#xff0c;宏替换&#xff0c…

No module named 'Tkinter'

sudo apt install python3-tk这一句就搞定了。网上长篇大论也真是醉了

Linux gcc 制作静态库01

制作步骤 编译为 .o 文件 createliba目录下 结构为 ├── head │ └── test.h ├── jia.c ├── jian.c ├── cheng.c ├── chu.c 这4个源文件&#xff0c;提供 - * /算数运算&#xff0c; 使用了 head目录下 test.h文件 先编译为.o文件 gcc -c *.c -I./head l…

Ubuntu 18的中文界面切换《图解教程》亲测成功

然后找到Chinese simple 把汉语挪到第一行

linux gcc 制作动态库

编译与位置无关的代码&#xff0c;生成.o&#xff0c;关键参数 -fPIC createlibso目录下 ├── cheng.c ├── chu.c ├── head │ └── test.h ├── jia.c └── jian.cgcc -fPIC -c *.c -I ./head在createlibso目录下生成 与位置无关的.o文件 ├── cheng.c ├…

Ubuntu的中文是哪种字体?python的词云分析和 三国演义人物出场统计

Ubuntu的默认中文是哪种呢&#xff1f; fc-list :langzh 用这个命令查看出来 NotoSerifCJK-Bold.ttc 为什么要知道这个呢&#xff1f; 来看一块python3代码 import jieba import wordcloudf open("threekingdom.txt","rb") t f.read() f.close() ls …

linux 系统课程-进程控制01

进程的状态转化 进程拥有四种状态&#xff08;切换&#xff09;&#xff0c;他们之间的关系如图 运行 挂起 终止 就绪内存管理单元 MMU &#xff08;Memory Management Unit&#xff09; mmu 负责 a. 虚拟内存与物理内存的映射 b. 设置内存的访问级别 pcb 进程控制块 环…

linux c++ 多进程初步01

fork函数 fork函数 ps ajx 这个命令可以查看进程与进程之间的血缘关系 kill 给进程发送一个信号SIGKILL 9号信号kill -SIGKILL pik 杀死进程进程共享 子进程会复制父进程的几乎所有信息&#xff1a;子进程复制父进程用户空间所有数据&#xff1b; 子进程复制父进程内核空间P…

Ubuntu怎么设置桌面快捷方式(图片详解)

然后找到你要的copy然后到桌面&#xff0c;点开然后允许权限&#xff01;就搞定了

linux C++ 多进程初步02

ps:疑惑的地方&#xff0c;1 进程pcb的概念&#xff0c; 还有 ulimit -a 显示的信息 是一个进程可以最大占用资源的上限吗&#xff1f; 还有 文件描述符的概念&#xff1f;&#xff1f; 这里不是很明白&#xff01;记录一下2还有WIFEXITED 孤儿进程 与僵尸进程 孤儿进程&#…

Linux C语言C++ makefile文件编写

ps: 这里 不是很明白&#xff1f;尤其是 后面 三个变量&#xff0c;什么区别&#xff1f; $ 代表目标 $^ 代表全部依赖 $< 第一个依赖 $? 第一个变化的依赖 makefile makefile 命名规则makefileMakefilemakefile 三要素目标依赖规则命令 写法&#xff1a; 目标:依赖 tab键…

Ubuntu升级

apt-get update: 升级安装包相关的命令,刷新可安装的软件列表(但是不做任何实际的安装动作) apt-get upgrade: 进行安装包的更新(软件版本的升级) apt-get dist-upgrade: 进行系统版本的升级(Ubuntu版本的升级) do-release-upgrade: Ubuntu官方推荐的系统升级方式,若加参数-…

软件工程学习笔记《一》什么是软件工程

文章目录软件工程学习笔记目录软件工程过程软件工程方法软件质量软件质量如何评价软件的质量模型ISO9126模型易用性&#xff1a;效率可维护性可移植性为什么内存缓冲区是2048或4096软件工程学习笔记目录 [https://blog.csdn.net/csdn_kou/article/details/83754356] 单纯摆出一…

linux C语言 文件相关知识01

ps:文件描述符表&#xff0c;与文件指针 有什么联系&#xff1f;&#xff1f;&#xff1f; 1. linux 系统&#xff0c;一般一个进程 允许打开的最大文件数量是 1024&#xff0c; 对应内核区的进程控制块&#xff08;pcb&#xff09;中的文件描述符表的范围&#xff0c; 在shell…

linux 系统函数调用:open close read write lseek

open函数 查看函数原型 man 2 open #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode);相关参数用法介绍&#xff1b; a. pathname …

PyCharm安装和配置教程

文章目录官网链接错误类型&#xff01;1.你的用户名是中文解决方案PyCharm的汉化和配置PyCharm的简单使用入门PyCharm和git安装教程官网链接 www.jetbrains.com 错误类型&#xff01;1.你的用户名是中文 安装第一次各种问题&#xff01;就不多了&#xff0c;反正各种报错 原…