maven 自动打包 上传bat命令

需要使用到pscp.exp和plink.exe

 

shell脚本

#!/bin/bash

APP_NAME=myproject
APP_DIR=/usr/hdms
APP_PORT=18000

if [ "$1" = "" ];
then
    echo -e "\033[0;31m 未输入操作名 \033[0m  \033[0;34m {start|stop|restart|status} \033[0m"
    exit 1
fi

if [ "$APP_NAME" = "" ];
then
    echo -e "\033[0;31m 未输入应用名 \033[0m"
    exit 1
fi

function start()
{	 echo;
    PID=`netstat -tlnp | grep :$APP_PORT | awk '{print $7}'| awk -F '/' '{print $1}'`

	if [ $PID ]; then
	    	echo "$APP_NAME PORT:$APP_PORT is running..."
	else
		nohup java -jar $APP_DIR/myproject-1.0-SNAPSHOT.jar  > $APP_DIR/hdms.log &
		echo "Start $APP_NAME success..."
	fi
	 echo;
}

function stop()
{	 echo;
	 echo "Stop $APP_NAME"

	PID=""
	query(){
		PID=`netstat -tlnp | grep :$APP_PORT | awk '{print $7}'| awk -F '/' '{print $1}'`
	}

	query
	if [ $PID ]; then
		kill -TERM $PID
		echo "$APP_NAME (pid:$PID) exiting..."
		while [ $PID ]
		do
			sleep 1
			query
		done
		echo "$APP_NAME stop success"
	else
		echo "$APP_NAME already stopped."
	fi
	 echo;
}

function restart()
{
    stop
    sleep 2
    start
}

function status()
{	echo;
    PID=`netstat -tlnp | grep :$APP_PORT | awk '{print $7}'| awk -F '/' '{print $1}'`
    if [  $PID ];then
        echo "$APP_NAME PORT: $APP_PORT  is running..."
    else
        echo "$APP_NAME is not running..."
    fi
	 echo;
}

case $1 in
    start)
    start;;
    stop)
    stop;;
    restart)
    restart;;
    status)
    status;;
    *)
esac

 

bat脚本

@echo off
title auto-package myproject

echo +++++++++++++++++++++++++++++++++++++++++++
echo            begin package myproject
echo +++++++++++++++++++++++++++++++++++++++++++

set curdir=%~dp0
set user=root
set passwd=123456
set server_ip=10.20.13.160
set dir=/usr/myproject/

echo;
d:
cd %curdir%

echo ======== begin updata svn code =========
echo updata svn code...
TortoiseProc.exe /command:update /path:".\" /closeonend:0
echo ======== updata svn code success ========

echo;
echo;
echo ========  begin clean install ============
echo;
call mvn clean install -DskipTests
echo;
echo ========  clean install success ===========

echo;
if not exist "C:\Windows\System32\pscp.exe" goto copyExe
if not exist "C:\Windows\System32\plink.exe" goto copyExe
goto copyJar

:copyExe
echo ======== begin copy pscp.exe to C:\Windows\System32\ ========
echo copy pscp...
xcopy %curdir%\tools\pscp.exe C:\Windows\System32 /F/Y
xcopy %curdir%\tools\plink.exe C:\Windows\System32 /F/Y
echo +
echo +
if not exist "C:\Windows\System32\pscp.exe" goto copyExeFail
if not exist "C:\Windows\System32\plink.exe" goto copyExeFail

echo ======== copy pscp.exe success ========
goto copyJar

:copyExeFail
echo ======== copy pscp.exe fail ========
echo +
echo please run this bat with Administrator
echo +
echo +
goto fail

:copyJar
echo;
echo ======== begin copy jar to linux server ========
echo copy jar...
pscp -pw %passwd% %curdir%\target\*.jar %user%@%server_ip%:%dir%
pscp -pw %passwd% %curdir%\tools\myproject.sh %user%@%server_ip%:%dir%
plink -pw %passwd% %user%@%server_ip% "chmod +x /usr/myproject/myproject.sh"
echo;
echo ======== copy jar to linux server success ========
goto success

:success
echo +
echo +
echo +++++++++++++++++++++++++++++++++++++++++++
echo            package success
echo start application by run the command 'sh /usr/myproject/myproject.sh start'
echo +++++++++++++++++++++++++++++++++++++++++++
echo +
echo +

pause
exit

:fail
echo +
echo +
echo +++++++++++++++++++++++++++++++++++++++++++
echo            package fail
echo +++++++++++++++++++++++++++++++++++++++++++
pause
exit

 

 

你可能感兴趣的:(java)