md5.sh
#!/bin/bash
function showHelp()
{
echo "Usage: md5.sh [OPTION] ..."
echo " -create create md5 sums to L.MD5.CHECK"
echo " -check read MD5 sums from FILEs and check them"
}
function createMD5()
{
if [ -f ./$md5_file_name ]; then
echo -e "md5 file already exist: $md5_file_name
"
exit 1
fi
md5sum `find ./ -type f` > $md5_file_name
echo "$md5_file_name CREATED SUCCESS"
}
function checkMD5()
{
echo "CHECK FILE BEGIN..."
md5sum -c --quiet $md5_file_name
echo "CHECK FILE END."
}
# ----------------------------------------------------------------------------
echo -e "
"
md5_file_name=L.MD5.CHECK
case $1 in
"-cr" | "-create" )
createMD5
;;
"-c" | "-ch" | "-check" )
checkMD5
;;
* )
showHelp
;;
esac
echo -e "
"
tomcat重启
check.sh
#!/bin/bash
shell_home=$(cd `dirname $0`;pwd)
shell_name=`basename $0`
shell=${shell_home}/${shell_name}
function print() {
echo -e "e[36;1m $1$(tput sgr0)"
}
print "
begin ${shell_name}"
# --------------------------------------------------------------------
app_home=${TOMCAT_HOME}
count=$(jps -lvm | grep ${app_home} | wc -l)
jps -lvm | grep --color ${app_home}
# --------------------------------------------------------------------
print "end ${shell}! count=${count}
"
exit ${count}
start.sh
#!/bin/bash
shell_home=$(cd `dirname $0`;pwd)
shell_name=`basename $0`
shell=${shell_home}/${shell_name}
function print() {
echo -e "e[36;1m $1$(tput sgr0)"
}
print "
begin ${shell_name}"
# --------------------------------------------------------------------
export JAVA_OPTS="-server -Xms800m -Xmx800m"
export JPDA_ADDRESS=7878
# export JPDA_SUSPEND=y
# --------------------------------------------------------------------
app_home=${TOMCAT_HOME}
app_log=${app_home}/logs/catalina.out
print "rm -rf ${app_home}/work/*"
rm -rf ${app_home}/work/*
print "rm -rf ${app_home}/temp/*"
rm -rf ${app_home}/temp/*
echo -e "
`date "+%F %H:%M:%S"` start ---> bash ${app_home}/bin/catalina.sh jpda start <---
" >> ${app_log}
print "bash ${app_home}/bin/catalina.sh jpda start"
bash ${app_home}/bin/catalina.sh jpda start
print "tail -10f ${app_log}"
tail -10f ${app_log}
# --------------------------------------------------------------------
print "end ${shell}
"
kill.sh
#!/bin/bash
shell_home=$(cd `dirname $0`;pwd)
shell_name=`basename $0`
shell=${shell_home}/${shell_name}
function print() {
echo -e "e[36;1m $1$(tput sgr0)"
}
print "
begin ${shell_name}"
# --------------------------------------------------------------------
export JAVA_OPTS="-server -Xms800m -Xmx800m"
export JPDA_ADDRESS=7878
# export JPDA_SUSPEND=y
# --------------------------------------------------------------------
app_home=${TOMCAT_HOME}
app_log=${app_home}/logs/catalina.out
echo -e "
`date "+%F %H:%M:%S"` stop ---> jps -lvm | grep ${app_home} | awk 'print $1' | xargs -I {} kill -9 {} <---
" >> ${app_log}
print "jps -lvm | grep ${app_home} | awk '{print $1}' | xargs -I {} kill -9 {}"
jps -lvm | grep ${app_home} | awk '{print $1}' | xargs -I {} kill -9 {}
# --------------------------------------------------------------------
print "end ${shell}
"
restart.sh
#!/bin/bash
shell_home=$(cd `dirname $0`;pwd)
shell_name=`basename $0`
shell=${shell_home}/${shell_name}
function print() {
echo -e "e[36;1m $1$(tput sgr0)"
}
print "
begin ${shell_name}"
# --------------------------------------------------------------------
bash ${shell_home}/check.sh
bash ${shell_home}/kill.sh
bash ${shell_home}/start.sh
# --------------------------------------------------------------------
print "end ${shell}
"
查看系统运行状态信息
#!/bin/bash
clear
echo -e
# 显示颜色
reset_terminal=$(tput sgr0)
colour='e[1;32m'
# vmstat系统资源刷新次数
vmstat_refresh_time=3
# 测试网络状态时,ping的IP或地址
ping_url=baidu.com
# tomcat根目录,用于获取PID
tomcat_home="/home/chencye/tomcat/apache-tomcat-8.5.9"
# 查看tomcat版本的tomcat自带脚本
tomcat_version_shell=$tomcat_home"/bin/version.sh"
# tomcat的http端口,用于统计并发连接数
tomcat_port=8080
# app的链接,用于测试tomcat是否正常
tomcat_url=http://192.168.1.104:8080
# 查看tomcat的GC情况,刷新次数
tomcat_gc_refresh_time=5
# 系统信息-------------------------------------------------------
# 系统与内核相关信息
system_uname=$(uname -a)
echo -e $colour " 系统与内核(uname -a):" $reset_terminal $system_uname
# 当前Linux系统的发行版本
os_name=$(cat /etc/issue | sed 's/\//g')
echo -e $colour " 当前Linux系统的发行版本(/etc/issue):" $reset_terminal $os_name
echo -e
# 系统资源
echo -e $colour " 系统资源(vmstat 1 $vmstat_refresh_time):" $reset_terminal
vmstat 1 $vmstat_refresh_time
echo -e
# 当前登录用户
# echo -e $colour " 当前登录用户:" $reset_terminal
# who
# 磁盘-------------------------------------------------------
# 磁盘使用量
diskavege=$(df -P | grep -vE 'Filesystem|tmpfs|文件系统' | awk '{print $1 " " $5 ", " }')
echo -e $colour " 磁盘使用量(df -P):" $reset_terminal $diskavege
# 磁盘IO
echo -e $colour " 磁盘IO情况(iostat):" $reset_terminal
iostat
echo -e
# 内存-------------------------------------------------------
mem_usages=( $(awk '
/MemTotal/ { total = $2 }
/MemFree/ { free = $2 }
/^Cached/ { cached = $2 }
/Buffers/ { buffers = $2 }
END {
allUsage = total - free;
appUsage = allUsage - (cached + buffers);
total = total / 1024;
total_s = total < 1024 ? (total)"M" : (total / 1024)"G";
allUsage = allUsage / 1024;
allUsage_s = allUsage < 1024 ? (allUsage)"M" : (allUsage / 1024)"G";
appUsage = appUsage / 1024;
appUsage_s = appUsage < 1024 ? (appUsage)"M" : (appUsage / 1024)"G";
print total_s;
print allUsage_s;
all_percent = (allUsage / total) * 100;
print all_percent"%";
print appUsage_s;
app_percent = (appUsage / total) * 100;
print app_percent"%";
}
' /proc/meminfo
))
echo -e $colour " 总内存(/proc/meminfo):" $reset_terminal ${mem_usages[0]}
echo -e $colour " 总使用内存, 总使用占比:" $reset_terminal ${mem_usages[1]}", "${mem_usages[2]}
echo -e $colour " 应用使用内存, 应用使用占比:" $reset_terminal ${mem_usages[3]}", "${mem_usages[4]} " (减去Cached与Buffers)"
echo -e
# 负载-------------------------------------------------------
loadaverge=$(uptime)
echo -e $colour " 平均负载(uptime):" $reset_terminal $loadaverge
echo -e
# 网络-------------------------------------------------------
# 内网IP
# internalip=$(hostname -I)
# echo -e $colour " 内网IP:" $reset_terminal $internalip
# 公网IP
# externnalip=$(curl -s http://ipecho.net/plain)
# echo -e $colour " 公网IP:" $reset_terminal $externnalip
# DNS
# nameservers=$( cat /etc/resolv.conf | grep -E "<nameserver[ ]+" | awk '{print $NF}' )
# echo -e $colour " DNS:" $reset_terminal $nameservers
# 判断网络是否通畅 (公网IP)
netstatus=$(ping -c 2 $ping_url &> /dev/null && echo " 通畅 " || echo " ping不通 ")
echo -e $colour " 网络状态(ping $ping_url): " $reset_terminal $netstatus
echo -e
# 网络连接状态统计
echo -e $colour " 网络连接状态统计(netstat -n):" $reset_terminal
netstat -n | awk '
BEGIN { print "连接状态 连接数" }
/^tcp/ { ++states[$NF] }
END {
for (key in states) {
print key, " ", states[key];
}
}
'
echo -e
# tomcat-------------------------------------------------------
# 获取tomcat的PID
tomcat_pid=$(jps -lvm | grep $tomcat_home | awk '{print $1}')
# tomcat并发连接数
tomcatLinkNumber=$(netstat -na | grep ESTAB | grep $tomcat_port | wc -l)
echo -e $colour " tomcat并发连接数:" $reset_terminal $tomcatLinkNumber
echo -e
# tomcat是否通畅
tomcat_status_code=$(curl -m 5 -s -w %{http_code} $tomcat_url -o /dev/null)
echo -e $colour " tomcat链接($tomcat_url)返回码:" $reset_terminal $tomcat_status_code
echo -e
# tomcat版本信息
echo -e $colour " tomcat版本信息($tomcat_version_shell):" $reset_terminal
sh $tomcat_version_shell
echo -e
# tomcat对应的jvm信息
echo -e $colour " tomcat对应的jvm信息(jinfo $tomcat_pid):" $reset_terminal
jinfo $tomcat_pid &> /tmp/$tomcat_pid".jinfo"
jvminfos="java.version|java.vendor|java.vm.version|java.vm.vendor|java.vm.name|java.runtime.version|java.class.version|java.io.tmpdir|user.dir|user.name|user.home|user.language|file.encoding|catalina.home|catalina.base|VMsflags|Commandsline"
grep -Pi $jvminfos /tmp/$tomcat_pid".jinfo"
echo -e
rm -f /tmp/$tomcat_pid".jinfo"
# tomcat的GC情况
echo -e $colour " tomcat的GC情况(jstat -gc $tomcat_pid 1000 $tomcat_gc_refresh_time):" $reset_terminal
jstat -gc $tomcat_pid 1000 $tomcat_gc_refresh_time
echo -e