shell脚本
#!/bin/bash
. /home/dky/.profile ##配置文件应用
start1=" java -Dfile.encoding=utf-8 -jar -Duser.timezone=GMT+8 *xxl*job*"
start2=" java -javaagent:sjt_agent.jar -Dfile.encoding=utf-8 -jar -Duser.timezone=GMT+8 *xxl*job*"
start3=" java -javaagent:sjt_agent.jar -jar -Duser.timezone=GMT+8 -Dloader.path=region/ -jar dmias-robot-*.jar --spring.profiles.active=dev"
##path
APath="/home/dky/robot/xxl-job/xxl-job-admin/*sjt*"
CPath="/home/dky/robot/xxl-job/cache-xxl-job-executor/*sjt*"
DPath="/home/dky/robot/xxl-job/dmias-xxl-job-executor/*sjt*"
TPath="/home/dky/robot/xxl-job/time-xxl-job-executor/*sjt*"
##停止方法
stop () {
select var in "StopMain" "StopAdmin" "StopCache" "StopDmias" "StopTime" "StopAll" "For" "Quit"
do
case $var in
StopMain)
netstat -nlp | grep 18081 | awk '{print $NF}'| cut -d "/" -f 1|xargs -I {} kill -9 {}
sleep 1
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
;;
StopAdmin)
netstat -nlp | grep 19999 | awk '{print $NF}'| cut -d "/" -f 1|xargs -I {} kill -9 {}
sleep 1
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
;;
StopCache)
netstat -nlp | grep 19910| awk '{print $NF}'| cut -d "/" -f 1|xargs -I {} kill -9 {}
sleep 1
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
;;
StopDmias)
netstat -nlp | grep 19911 | awk '{print $NF}'| cut -d "/" -f 1 | xargs -I {} kill -9 {}
sleep 1
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
;;
StopTime)
netstat -nlp | grep 19912 | awk '{print $NF}'| cut -d "/" -f 1 |xargs -I {} kill -9 {}
sleep 1
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
;;
StopAll)
ps -ef | grep xx[l] | awk '{print $2}' | xargs -I {} kill -9 {}
sleep 1
exit
if [ $? -eq 0 ]
then
echo "Stop Yes"
else
echo "Stop No"
fi
exit
;;
For)
select for in "StopServer" "StartServer" "Quit"
do
case $for in
StopServer)
stop
;;
StartServer)
start
;;
Quit)
exit
esac
done
;;
Quit)
exit
esac
done
}
##启动方法
start () {
select var in "StartMain" "StartAdmin" "StartCache" "StartDmias" "StartTime" "StartAll" "For" "Quit"
do
case $var in
StartMain)
Main && nohup $start3 &
sleep 1
echo "Main正在启动中..."&& sleep 9
if [[ `ps -ef | grep dmias-robo[t]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep dmias-robo[t]
;;
StartAdmin)
if [ -e $APath ]
then
XxlAdmin && nohup $start2 &
sleep 1
echo "Admin正在启动中..."&& sleep 9
if [[ `ps -ef | grep xxl-job-admi[n]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl-job-admi[n]
else
XxlAdmin && nohup $start1 &
sleep 1
echo "Admin正在启动中..."&& sleep 9
if [[ `ps -ef | grep xxl-job-admi[n] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl-job-admi[n]
fi
;;
StartCache)
if [ -e $CPath ]
then
XxlCache && nohup $start2 &
sleep 1
echo "Cache正在启动中..."&& sleep 9
if [[ `ps -ef | grep cache.*xxl.*jo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep cache.*xxl.*jo[b]
else
XxlCache && nohup $start1 &
sleep 1
echo "Cache正在启动中..."&& sleep 9
if [[ `ps -ef | grep cache.*xxl.*jo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep cache.*xxl.*jo[b]
fi
;;
StartDmias)
if [ -e $DPath ]
then
XxlDmias && nohup $start2 &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep dmias.*xxl.*jo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep dmias.*xxl.*jo[b]
else
XxlDmias && nohup $start1 &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep dmias.*xxl.*jo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep dmias.*xxl.*jo[b]
fi
;;
StartTime)
if [ -e $TPath ]
then
XxlTime && nohup $start2 1>>nohup.out 2>>tmp &
sleep 1
echo "Time正在启动中..."&& sleep 9
if [[ `ps -ef | grep time-xxljo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep ps -ef | grep xxl.*jo[b]
else
XxlTime && nohup $start1 1>>nohup.out 2>>tmp &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep time-xxljo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl.*jo[b]
fi
;;
StartAll)
if [ -e $APath ]
then
XxlAdmin && nohup $start2 &
sleep 1
echo "Admin正在启动中..."&& sleep 9
if [[ `ps -ef | grep xxl-job-admi[n] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl-job-admi[n]
else
XxlAdmin && nohup $start1 &
sleep 1
echo "Admin正在启动中..."&& sleep 9
if [[ `ps -ef | grep xxl-job-admi[n] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl-job-admi[n]
fi
sleep 5
if [ -e $CPath ]
then
XxlCache && nohup $start2 &
sleep 1
echo "Cache正在启动中..."&& sleep 9
if [[ `ps -ef | grep cache.*xxl.*jo[b] |wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep cache.*xxl.*jo[b]
else
XxlCache && nohup $start1 &
sleep 1
echo "Cache正在启动中..."&& sleep 9
if [[ `ps -ef | grep cache.*xxl.*jo[b]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep cache.*xxl.*jo[b]
fi
sleep 5
if [ -e $DPath ]
then
XxlDmias && nohup $start2 &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep dmias.*xxl.*jo[b]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep dmias.*xxl.*jo[b]
else
XxlDmias && nohup $start1 &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep dmias.*xxl.*jo[b]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep dmias.*xxl.*jo[b]
fi
sleep 5
if [ -e $TPath ]
then
XxlTime && nohup $start2 1>>nohup.out 2>>tmp &
sleep 1
echo "Time正在启动中..."&& sleep 9
if [[ `ps -ef | grep time-xxljo[b]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl.*jo[b]
else
XxlTime && nohup $start1 1>>nohup.out 2>>tmp &
sleep 1
echo "Dmias正在启动中..."&& sleep 9
if [[ `ps -ef | grep time-xxljo[b]|wc -l` -eq 1 ]]
then
echo "启动成功"
else
echo "启动失败,请检查"
fi
sleep 2 && echo "######进程信息#######"
ps -ef | grep xxl.*jo[b]
fi
;;
For)
select for in "StopServer" "StartServer" "Quit"
do
case $for in
StopServer)
stop
;;
StartServer)
start
;;
Quit)
exit
esac
done
;;
Quit)
exit
esac
done
}
##方法调用
PS3="Please Input Number : "
select for in "StopServer" "StartServer" "Quit"
do
case $for in
StopServer)
stop
;;
StartServer)
start
;;
Quit)
exit
esac
done
;;
Quit)
exit
esac
done