simple tomcat tool

目录:

linux下mysql备份脚本

simple tomcat sh

tomcat 6 下开启远程调试

java启动命令

使用expect交互脚本进行scp密码输入
rsync复用ssh通道进行文件传输
crontab -e

 查看tcpdump

gen md5 code

 

linux下mysql备份脚本

#!/bin/bash

echo $(date +"%Y-%m-%d %H:%M:%S") backup begin

/usr/local/mysql/bin/mysqldump -u root -pmysqladmin --all-databases | gzip -9 > "/data/backup/$(date +"%Y%m%d").sql.gz"

echo $(date +"%Y-%m-%d %H:%M:%S") backup end

 

 

0.simple tomcat sh:

 

 

ps -ef | awk '/tomcat/{print "kill " $2}' | sh    

 

语法:awk '/正则表达式/{print }'

 

ps -ef | grep java | awk '{print "kill "$2}' | sh

 

 

1.这个是修改后的文件,比起之前那个简单了一点,不用生成中间文件。

 

 

 

excu=`ps -ef | grep tomcat | awk '{print $2}'`
kill $excu;

#start the tomcat server
if [ $1 ]; then
sh pageapi/tomcat/bin/startup.sh
fi

 

 

2.添加usage和命令选择的

ACTION=$1
usage()
{
 echo "Usage arg : stop | start | restart";
}

stop()
{
 excu=`ps -ef | grep tomcat | awk '{print $2}'`
 kill $excu;
}

start()
{
 sh pageapi/tomcat/bin/startup.sh
}

case "$ACTION" in
        stop)
                stop
        ;;
        start)
         start
        ;;
        restart)
         stop
         start
        ;;
        *)
         usage
        ;;
esac

 

 

 

 

 

 

 

3.最初的文件,生成中间文件 

 

每次都ps -ef | grep tomcat太累啦~~~~

 

1.tomcatutil.sh脚本:执行后删除tomcat进程

#delete tomcat process
ps -ef | grep tomcat | awk '{print "kill "$2}' > kill2.sh
chmod +x kill2.sh
sh kill2.sh

#if the arg is not null ;start the tomcat server
if [ $1 ]; then
sh pageapi/tomcat/bin/startup.sh
fi

 

2.如果希望重启,随便给一个参数,就重启啦:

tomcatutil.sh start

 

 

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

-------------------------------------------------------

 
 
测试项目发布在tomcat上,不是jboss,每次都ps -ef | grep tomcat太累啦~~~~

tomcatutil.sh脚本:执行后删除tomcat进程

 #delete tomcat process                                           
ps -ef | grep tomcat | awk '{print "kill "$2}' > kill2.sh     
chmod +x kill2.sh                                                     
sh kill2.sh                                                                
rm kill2.sh                                                                
                                                                              
#if the arg is not null ;start the tomcat server               
if [ $1 ]; then                                                             
sh pageapi/tomcat/bin/startup.sh                               
fi                                                                             

ps -ef 
输出process
 
grep tomcat
输出tomcat进程,与同部署一起的jboss无关
 
awk '{print "kill "$2}'
将进程号输出
 
> kill2.sh 
保存到文件
 
chmod +x kill2.sh
添加执行操作
 
if [ $1 ]; then
如果有参数
 
sh pageapi/tomcat/bin/start.sh
执行相对路径的start
 
 
demo:
./tomcatutil.sh
杀掉tomcat,然后可以部署新机器
 
./tomcatutil.sh aaaa
随便一个参数就重启~~偷懒行为~~~
 
tomcat 6 下开启远程调试
linux下修改catalina.sh:
JAVA_HOME=/usr/local/jdk1.6
if [ "$1" = "start" ] ; then
  rm -Rf ../work/Catalina
  JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Xms256m -Xmx512m -XX:PermSize=64m -XX:M
axPermSize=256m -XX:+PrintGCDetails -Xloggc:../logs/gc$$.log -XX:+HeapDumpOnOutOfMemoryError "
fi
 
window下修改startup.bat:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
 
java启动命令
#!/bin/bash


JAVA_HOME=/usr/local/jdk1.6
JAVA_OPTS="-Xms64m -Xmx128m"
CLASSPATH=${CLASSPATH}:"/usr/local/loganalyse/classes":`echo /usr/local/loganalyse/lib/*.jar | sed "s/ /:/g"`

echo $(date +"%Y-%m-%d %H:%M:%S")" start LogReader"

if [ -z "${JAVA_HOME}" ] ; then
    echo "JAVA_HOME"
    echo "Please set JAVA_HOME"
    exit 1
fi
if [ ! -x "${JAVA_HOME}/bin/java" ] ; then
    echo "JAVA_HOME Error"
    echo "Can not find Java VM"
    exit 1
fi

echo "Using JAVA_HOME   ${JAVA_HOME}"
echo "Using CLASSPATH   ${CLASSPATH}"

"${JAVA_HOME}/bin/java" ${JAVA_OPTS} -cp ${CLASSPATH} com.tenpay.open.loganalyse.reader.LogReader

echo $(date +"%Y-%m-%d %H:%M:%S")" end LogReader"
                                                        
 
linux交互式应答
#!/usr/bin/expect --

if { [llength $argv] != 5  } {
  puts "Usage: $argv0  srcFile dstFile IP user passwd"
  exit 1
}
set timeout  3000
#/usr b/postfix/spawn ssh -l[lindex $argv 1] -p36000 [lindex $argv 0] -q "[lindex $argv 3]"
spawn rsync -azuv --progress -e "/usr/local/bin/ssh -q -p36000" [lindex $argv 3]@[lindex $argv 2]:[lindex $argv 0] [lindex $argv 1]

expect {
                "*(yes )*" {send "yes\n"; exp_continue;}
                 "*password*" {send "[lindex $argv 4]\n"; exp_continue;}
                 timeout { exec kill -9 [exp_pid]; close; }
        }
 
使用expect交互脚本进行scp密码输入
rsync复用ssh通道进行文件传输
#!/usr/bin/expect --

if { [llength $argv] != 5  } {
  puts "Usage: $argv0  srcFile dstFile IP user passwd"
  exit 1
}
set timeout  3000
#/usr/shdb/postfix/spawn ssh -l[lindex $argv 1] -p36000 [lindex $argv 0] -q "[lindex $argv 3]"
spawn rsync -azuv --progress -e "/usr/local/bin/ssh -q -p36000" [lindex $argv 3]@[lindex $argv 2]:[lindex $argv 0] [lindex $argv 1]

expect {
                "*(yes/no)*" {send "yes\n"; exp_continue;}
                "*password*" {send "[lindex $argv 4]\n"; exp_continue;}
                timeout { exec kill -9 [exp_pid]; close; }
}
 
crontab -e :注意时间起码要大于date里面显示多3分钟,保证cron命令能执行
#open api log analyse
40 * * * * /usr/local/loganalyse/loganalyse.sh >> /usr/local/loganalyse/result.log 2>&1

#download 145 api 
20 * * * * /data/loganalyse/filedownload.sh >> /data/loganalyse/result.log 2>&1
 
查看tcpdump
tcpdump -i any -X -s 2000 -n port 25550 
 
gen md5 code
find [directory_name] -type f -print0 | xargs -0 md5sum > md5_result.txt
 

你可能感兴趣的:(java,tomcat,linux,mysql,ssh)