端口检测并报警 不指定

kangyang , 2014/07/21 16:41 , SHELL脚本 , 评论(0) , 阅读(3471) , Via 本站原创

#!/bin/bash
#检测服务器端口是否开放,成功会返回0值显示ok,失败会返回1值显示fail  
PWD=`pwd`
port=9888
date=`date +"%Y-%m-%d %H:%M:%S"`


Rsync_exec(){
        expect -c "
        set timeout 600;
        spawn rsync -rpogtvae \"ssh -p 1918\" root@114..11.11.11:/home/python-ssh/hostlist  /home/soft
        expect {
                \"*yes/no*\" {send \"yes\r\";exp_continue}
                \"*password*\" {send \"xxxxx\r\";}
        }
        expect eof;"
}
Rsync_exec



echo "----------------------$date 以下游戏服9888端口没启动请检查!--------------------" >$PWD/port_closed_status

while read line
do
  nc -w 40 -z $line $port > /dev/null 2>&1
  if [ $? -eq 0 ]; then
  echo "$line--$port端口status: 开启!"
  else
  echo "$line--$port端口status: 关闭!"
  echo "$line--$port端口status: Closed" >>$PWD/port_closed_status
  fi
sleep 1;
done<$PWD/hostlist


cat $PWD/port_closed_status


#send mail
closed=`cat $PWD/port_closed_status | grep Closed`
if [ "$closed" != "" ]
then
iconv -f utf-8 -t gb2312 $PWD/port_closed_status | tee $PWD/port_closed_status.txt > /dev/null
mail -s "Server Port Status " xxxxxxx@qq.com < $PWD/port_closed_status.txt -- -f monitor@t4game.com
fi

java进程打印堆栈信息 不指定

kangyang , 2014/07/21 16:40 , SHELL脚本 , 评论(0) , 阅读(3346) , Via 本站原创
#################此脚本在游戏服出现故障时可以打印java进程内堆栈信息#######################
jstack脚本

#!/bin/bash
port=3888
time=`date +%Y-%m-%d-%H-%M`
pid=`netstat -tlnp | grep $port | awk '{ print $7}' | sed "s/\/java//g"`

#打印堆栈信息
jstack -l ${pid} > jstack-${pid}-${time}.log

#打印进程占用cpu情况
top -b -n 1 -H -p ${pid} > top-${pid}-${time}.log



################此脚本详细的打印出java虚拟机的详细堆栈信息#############################
jmap脚本

#!/bin/bash
#dump进程内存切片
time=`date +%Y-%m-%d-%H-%M`
pid=`netstat -tlnp | grep 3888 | awk '{ print $7}' | sed "s/\/java//g"`
jmap -dump:live,format=b,file=$pid.bin_${time} $pid

LINUX--rm命令改造脚本V2版本 不指定

kangyang , 2014/07/21 16:39 , SHELL脚本 , 评论(0) , 阅读(3752) , Via 本站原创
此脚本为linux下rm命令改造脚本,alias rm命令为mv命令,避免以后误删数据造成无法挽回的局面

一、如何试用
  1、执行lr命令是显示回收站数据
  2、删除文件直接rm file即可

二、v2版本增加了被删除的文件加上当前时间戳

#!/bin/bash

mkdir -p ~/.trash
cat >> .bashrc <<EOF
alias rm=trash
alias lr='ls ~/.trash'
alias ur=undelfile
alias cr=cleartrash


undelfile()
{
  mv -i ~/.trash/$@ ./
}

trash()
{
  mv $@ ~/.trash/$@.`date +%Y%m%d%H%M`
}

cleartrash()
{
    read -p "clear sure?[n]" confirm
    [ $confirm == 'y' ] || [ $confirm == 'Y' ]  && /bin/rm -rf ~/.trash/* && echo "clear ok!"
}
EOF
分页: 2/7 第一页 上页 1 2 3 4 5 6 7 下页 最后页 [ 显示模式: 摘要 | 列表 ]