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.pswp.cn/news/382539.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382539.shtml
英文地址,請注明出處:http://en.pswp.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;反正各種報錯 原…