热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

sh-脚本学习启动/停止/重启/部署jettycrontab

jettytest.sh#!binshjettysh_pathusrlocaljettybinjetty

===============jettytest.sh ======================

#!/bin/sh
jettysh_path=/usr/local/jetty/bin/jetty.sh

#jetty目录
jetty_home=/usr/local/jetty

#当前目录绝对路径
now_path=$(dirname $(readlink -f $0))

#jetty项目部署路径
jetty_workPath="/usr/local/jetty/webapps/ROOT/"

#部署war文件
RestUserWar=${now_path}/RestUser.war

NO_START=0

ACTION=$1

#NAME=$(echo $(basename $0) | sed -e 's/^[SK][0-9]*//' -e 's/\.sh$//')

#echo 当前路径now_path ${now_path}

echo ${jetty_workPath}


function deployJetty(){
echo ”准备部署...”
#sleep 1
if [ -d "$jetty_workPath" ]
then
echo "目录下已存在,是否重新部署?(y/n)"
read -p "请输入:" aoso
[ -z ${aoso} ] && aoso="n"
if [ "${aoso}" == "y" ] || [ "${aoso}" == "y" ]
then
echo "开始清理目录 ${jetty_workPath} ..."
rm -rf ${jetty_workPath} >/dev/null 2>&1
sleep 1
echo "清理完成"
else
echo "退出部署"
exit 1
fi
fi
if [ ! -s "$RestUserWar" ]
then
echo "没有找到war包,请将war包置入本目录下.."
else
echo "正在解压项目……"
unzip -o RestUser.war -d ${now_path}/ROOT
sleep 5
if [ $? -ne 0 ]
then
echo "项目解压失败!"
exit 1
fi
if [ $? -eq 0 ]
then
echo "解压完成……"
echo "正在部署"
mv ${now_path}/ROOT ${jetty_workPath}
fi
sleep 2
if [ $? -eq 0 ]
then
echo "部署完成"
rm -rf ${now_path}/ROOT
exit 0
else
echo "部署失败"
rm -rf ${now_path}/ROOT
echo "清理解压文件"
exit 1
fi
fi
}


case "$ACTION" in
start)
echo -n " 尝试启动 jetty... "
cd ${jetty_home}/bin

#if(( NO_START )); then
./jetty.sh start
cd ${now_path}
;;

stop)
echo -n " 尝试关闭 jetty... "
cd ${jetty_home}/bin
./jetty.sh stop
cd ${now_path}
;;

restart)
echo -n " 重启jetty .. "
cd ${jetty_home}/bin
./jetty.sh restart
cd ${now_path}
;;

deploy)
deployJetty
;;
*)
echo "命令: start | stop | restart | deploy"
esac

 

 

 

 ===================logcp.sh====================================

#!/bin/sh

cur_time=`date +%Y-%m-%d_%H:%M:%S`
log_path=/usr/local/nginx/logs
log=${log_path}/access.log
log_cut_path=${log_path}/awklog
log_cut=${log_cut_path}/access.${cur_time}.log

echo ${cur_time}

cp $log $log_cut
echo "" > $log

 

 

============================totaltest ===================================

#!/bin/sh

data_now=`date +"%Y-%m-%d %H:%M:%S"`

cur_time=`date +%Y%m%d_%H%M%S`
log_dir=/usr/local/nginx/logs

#nginx日志路径
nginx_accesslog=/usr/local/nginx/logs/access.log
nginx_curlog=${log_dir}/awklog/log_${cur_dir}.log

#controller以及项目日志路径
work_log_Path=/usr/local/RestUser/logs

#log
debug_log=${work_log_Path}/restUser_debug.log
error_log=${work_log_Path}/restUser_error.log

#统计行数
echo 当前时间 >> body.txt
#${data_now} >> body.txt

uptime >> body.txt

echo 总数据:>> body.txt
cat ${nginx_accesslog} | wc -l >> body.txt


echo 总访问HTTP >> body.txt
grep -o 'HTTP/1' ${nginx_accesslog} | wc -l >> body.txt

echo 访问时长 最长的前五个 >> body.txt
#cat ${nginx_accesslog} | awk '{pring $24}'
#cat /usr/local/nginx/logs/access.log | awk '{print $24}'
awk '{print $24}' ${nginx_accesslog} | sort -nr | head -n 5 >> body.txt

echo 统计ip 去掉重复值 >> body.txt
awk '{print $1}' ${nginx_accesslog} | sort -n | uniq | wc -l >> body.txt

echo 查看ip访问最多的前五个 >> body.txt
awk '{print $1}' ${nginx_accesslog} | sort | uniq -c | sort -rn | head -n 5 >> body.txt

echo 统计info记录数: >> body.txt
grep "info 日志记录" ${debug_log} | wc -l >> body.txt
echo controller响应时长 最快: >> body.txt
grep "Controller开始时间" ${debug_log} | awk '{print $9,$10}' | sort -rn | head -n 1 >> body.txt
echo db响应时长 最快: >> body.txt
grep "UserServiceImpl开始时间" ${debug_log} | awk '{print $9,$10}' | sort -rn | head -n 1 >> body.txt
echo controller 最慢: >> body.txt
grep "Controller开始时间" ${debug_log} | awk '{print $9,$10}' | sort -n | head -n 1 >> body.txt
echo db响应时长 最慢: >> body.txt
grep "UserServiceImpl开始时间" ${debug_log} | awk '{print $9,$10}' | sort -n | head -n 1 >> body.txt

read -p "是否发送邮件[y/n]: " aoso
[ -z ${aoso} ] && aoso="n"
if [ "${aoso}" == "y" ] || [ "${aoso}" == "Y" ]
then
echo "发送邮件中……"
mail -s 'Test mail' 0394anger@163.com else
echo "没有发送邮件"
fi 

 

 

============================sendmail===================================

vi  /etc/mail.rc

# sendmailconfig
set from=0394anger@163.com
set smtp=smtp.163.com
set smtp-auth-user=0394anger@163.com
set smtp-auth-password=sqm
set smtp-auth=login

============================  crOntab===================================

 

[root@VM_129_126_centos ~]# crontab -e

*/1 * * * * /usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &
0 0 * * * /usr/local/testsh/logcp.sh

============================ ===================================

 

============================ ===================================

 

============================ ===================================

 


推荐阅读
author-avatar
天勤-科技
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有