1.windows任务返回结果gbk转utf8
2.windows远程任务判断是否有效命令 3.添加windows运行脚本 4.添加package构造脚本 5.更新readme.md
14
README.md
@@ -33,13 +33,13 @@ V1.x版本是一个简单的定时任务管理系统,进入V1.0 :https://git
|
||||
|
||||
先看效果
|
||||
----
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
|
||||
安装方法
|
||||
|
||||
34
build.sh
@@ -1,34 +0,0 @@
|
||||
#!/bin/bash
|
||||
# @Author: Bee
|
||||
# @Date: 2019-02-17 08:38:58
|
||||
# @Last Modified by: Bee
|
||||
# @Last Modified time: 2019-02-17 08:38:58
|
||||
|
||||
version=$1
|
||||
|
||||
command -v tar >/dev/null 2>&1 || { echo >&2 "请检查tar是否已安装!"; exit 1; }
|
||||
command -v go >/dev/null 2>&1 || { echo >&2 "请检查golang是否已安装或环境变量是否正确!"; exit 1; }
|
||||
|
||||
if [[ ! -n "$version" ]];then
|
||||
echo "请执行如:"
|
||||
echo "$0 1.0.0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -d "build" ]];then
|
||||
mkdir build
|
||||
fi
|
||||
|
||||
go build -o PPGo_Job
|
||||
|
||||
cp -r -p PPGo_Job build/PPGo_Job
|
||||
cp -r -p ppgo_job2.sql build/ppgo_job2.sql
|
||||
cp -r -p run.sh build/run.sh
|
||||
cp -r -p conf build/conf
|
||||
cp -r -p static build/static
|
||||
cp -r -p views build/views
|
||||
rm -rf build/static/imgs
|
||||
|
||||
cd build && tar zcvf ../PPGo_Job-$version.tar.gz .
|
||||
|
||||
rm -rf ../build
|
||||
10
jobs/job.go
@@ -100,7 +100,7 @@ func NewCommandJob(id int, name string, command string) *Job {
|
||||
cmd.Start()
|
||||
err, isTimeout := runCmdWithTimeout(cmd, timeout)
|
||||
|
||||
return bufOut.String(), bufErr.String(), err, isTimeout
|
||||
return gbkAsUtf8(bufOut.String()), gbkAsUtf8(bufErr.String()), err, isTimeout
|
||||
}
|
||||
return job
|
||||
}
|
||||
@@ -280,11 +280,13 @@ func RemoteCommandJobByTelnetPassword(id int, name string, command string, serve
|
||||
}
|
||||
|
||||
_, err = conn.Read(buf)
|
||||
if err != nil {
|
||||
return "", "", err, false
|
||||
}
|
||||
|
||||
out = out + gbkAsUtf8(string(buf[:]))
|
||||
if err != nil ||
|
||||
strings.Contains(out, "'"+c+"' is not recognized as an internal or external command") ||
|
||||
strings.Contains(out, "'"+c+"' 不是内部或外部命令,也不是可运行的程序") {
|
||||
return "", "", fmt.Errorf(gbkAsUtf8(string(buf[:]))), false
|
||||
}
|
||||
}
|
||||
|
||||
return out, "", nil, false
|
||||
|
||||
209
package.sh
Executable file
@@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env bash
|
||||
# @Author: ouqiang
|
||||
# @Link https://github.com/ouqiang/gocron
|
||||
# @Last Modified by: Bee
|
||||
# @Last Modified time: 2019-02-18 10:22:13
|
||||
|
||||
# 生成压缩包 xx.tar.gz或xx.zip
|
||||
# 使用 ./package.sh -a amd64 -p linux -v v2.0.0
|
||||
|
||||
# 任何命令返回非0值退出
|
||||
set -o errexit
|
||||
# 使用未定义的变量退出
|
||||
set -o nounset
|
||||
# 管道中任一命令执行失败退出
|
||||
set -o pipefail
|
||||
|
||||
eval $(go env)
|
||||
|
||||
# 二进制文件名
|
||||
BINARY_NAME=''
|
||||
# main函数所在文件
|
||||
MAIN_FILE=""
|
||||
|
||||
# 提取git最新tag作为应用版本
|
||||
VERSION=''
|
||||
# 最新git commit id
|
||||
GIT_COMMIT_ID=''
|
||||
|
||||
# 外部输入的系统
|
||||
INPUT_OS=()
|
||||
# 外部输入的架构
|
||||
INPUT_ARCH=()
|
||||
# 未指定OS,默认值
|
||||
DEFAULT_OS=${GOHOSTOS}
|
||||
# 未指定ARCH,默认值
|
||||
DEFAULT_ARCH=${GOHOSTARCH}
|
||||
# 支持的系统
|
||||
SUPPORT_OS=(linux darwin windows)
|
||||
# 支持的架构
|
||||
SUPPORT_ARCH=(386 amd64)
|
||||
|
||||
# 编译参数
|
||||
LDFLAGS=''
|
||||
# 需要打包的文件
|
||||
INCLUDE_FILE=()
|
||||
# 打包文件生成目录
|
||||
PACKAGE_DIR=''
|
||||
# 编译文件生成目录
|
||||
BUILD_DIR=''
|
||||
|
||||
# 获取git 最新tag name
|
||||
git_latest_tag() {
|
||||
local COMMIT_ID=""
|
||||
local TAG_NAME=""
|
||||
COMMIT_ID=`git rev-list --tags --max-count=1`
|
||||
TAG_NAME=`git describe --tags "${COMMIT_ID}"`
|
||||
|
||||
echo ${TAG_NAME}
|
||||
}
|
||||
|
||||
# 获取git 最新commit id
|
||||
git_latest_commit() {
|
||||
echo "$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
# 打印信息
|
||||
print_message() {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
# 打印信息后推出
|
||||
print_message_and_exit() {
|
||||
if [[ -n $1 ]]; then
|
||||
print_message "$1"
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 设置系统、CPU架构
|
||||
set_os_arch() {
|
||||
if [[ ${#INPUT_OS[@]} = 0 ]];then
|
||||
INPUT_OS=("${DEFAULT_OS}")
|
||||
fi
|
||||
|
||||
if [[ ${#INPUT_ARCH[@]} = 0 ]];then
|
||||
INPUT_ARCH=("${DEFAULT_ARCH}")
|
||||
fi
|
||||
|
||||
for OS in "${INPUT_OS[@]}"; do
|
||||
if [[ ! "${SUPPORT_OS[*]}" =~ ${OS} ]]; then
|
||||
print_message_and_exit "不支持的系统${OS}"
|
||||
fi
|
||||
done
|
||||
|
||||
for ARCH in "${INPUT_ARCH[@]}";do
|
||||
if [[ ! "${SUPPORT_ARCH[*]}" =~ ${ARCH} ]]; then
|
||||
print_message_and_exit "不支持的CPU架构${ARCH}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 初始化
|
||||
init() {
|
||||
set_os_arch
|
||||
|
||||
if [[ -z "${VERSION}" ]];then
|
||||
VERSION=`git_latest_tag`
|
||||
fi
|
||||
GIT_COMMIT_ID=`git_latest_commit`
|
||||
LDFLAGS="-w -X 'main.AppVersion=${VERSION}' -X 'main.BuildDate=`date '+%Y-%m-%d %H:%M:%S'`' -X 'main.GitCommit=${GIT_COMMIT_ID}'"
|
||||
|
||||
PACKAGE_DIR=${BINARY_NAME}-package
|
||||
BUILD_DIR=${BINARY_NAME}-build
|
||||
|
||||
if [[ -d ${BUILD_DIR} ]];then
|
||||
rm -rf ${BUILD_DIR}
|
||||
fi
|
||||
# if [[ -d ${PACKAGE_DIR} ]];then
|
||||
# rm -rf ${PACKAGE_DIR}
|
||||
# fi
|
||||
|
||||
mkdir -p ${BUILD_DIR}
|
||||
mkdir -p ${PACKAGE_DIR}
|
||||
}
|
||||
|
||||
# 编译
|
||||
build() {
|
||||
local FILENAME=''
|
||||
for OS in "${INPUT_OS[@]}";do
|
||||
for ARCH in "${INPUT_ARCH[@]}";do
|
||||
if [[ "${OS}" = "windows" ]];then
|
||||
FILENAME=${BINARY_NAME}.exe
|
||||
else
|
||||
FILENAME=${BINARY_NAME}
|
||||
fi
|
||||
env CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -ldflags "${LDFLAGS}" -o ${BUILD_DIR}/${BINARY_NAME}-${OS}-${ARCH}/${FILENAME} ${MAIN_FILE}
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# 打包
|
||||
package_binary() {
|
||||
cd ${BUILD_DIR}
|
||||
|
||||
for OS in "${INPUT_OS[@]}";do
|
||||
for ARCH in "${INPUT_ARCH[@]}";do
|
||||
package_file ${BINARY_NAME}-${OS}-${ARCH}
|
||||
if [[ "${OS}" = "windows" ]];then
|
||||
zip -rq ../${PACKAGE_DIR}/${BINARY_NAME}-${VERSION}-${OS}-${ARCH}.zip ${BINARY_NAME}-${OS}-${ARCH}
|
||||
else
|
||||
tar czf ../${PACKAGE_DIR}/${BINARY_NAME}-${VERSION}-${OS}-${ARCH}.tar.gz ${BINARY_NAME}-${OS}-${ARCH}
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
cd ${OLDPWD}
|
||||
}
|
||||
|
||||
# 打包文件
|
||||
package_file() {
|
||||
if [[ "${#INCLUDE_FILE[@]}" = "0" ]];then
|
||||
return
|
||||
fi
|
||||
for item in "${INCLUDE_FILE[@]}"; do
|
||||
cp -r ../${item} $1
|
||||
done
|
||||
}
|
||||
|
||||
# 清理
|
||||
clean() {
|
||||
if [[ -d ${BUILD_DIR} ]];then
|
||||
rm -rf ${BUILD_DIR}
|
||||
fi
|
||||
}
|
||||
|
||||
# 运行
|
||||
run() {
|
||||
init
|
||||
build
|
||||
package_binary
|
||||
clean
|
||||
}
|
||||
|
||||
package_ppgo_job() {
|
||||
BINARY_NAME='PPGo_Job'
|
||||
MAIN_FILE="./main.go"
|
||||
INCLUDE_FILE=("conf" "static" "views" "ppgo_job2.sql" "run.sh" "run.bat")
|
||||
|
||||
run
|
||||
}
|
||||
|
||||
# p 平台 linux darwin windows
|
||||
# a 架构 386 amd64
|
||||
# v 版本号 默认取git最新tag
|
||||
while getopts "p:a:v:" OPT;
|
||||
do
|
||||
case ${OPT} in
|
||||
p) IPS=',' read -r -a INPUT_OS <<< "${OPTARG}"
|
||||
;;
|
||||
a) IPS=',' read -r -a INPUT_ARCH <<< "${OPTARG}"
|
||||
;;
|
||||
v) VERSION=$OPTARG
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
package_ppgo_job
|
||||
47
run.bat
Normal file
@@ -0,0 +1,47 @@
|
||||
@shift 1
|
||||
@echo off
|
||||
@title PPGoJob服务
|
||||
color 0A
|
||||
|
||||
chcp 65001
|
||||
|
||||
set curPath=%~dp0
|
||||
|
||||
:welcome
|
||||
cls
|
||||
echo.
|
||||
echo 1.启动
|
||||
echo 2.停止
|
||||
echo 3.重启
|
||||
echo.
|
||||
set /p input= 请输入代码(选1/2/3 直接回车):
|
||||
if not "%input%"=="" SET input=%input:~0,1%
|
||||
if "%input%"=="1" goto start
|
||||
if "%input%"=="2" goto stop
|
||||
if "%input%"=="3" goto restart
|
||||
cls
|
||||
echo.
|
||||
echo 选择无效,按任意键返回菜单
|
||||
echo.
|
||||
echo 现在是:%date% %time%
|
||||
@pause >nul
|
||||
goto welcome
|
||||
|
||||
:start
|
||||
start "PPGo_Job" /min PPGo_Job.exe
|
||||
echo 服务已启动...
|
||||
pause
|
||||
exit
|
||||
|
||||
:stop
|
||||
taskkill /f /t /im PPGo_Job.exe
|
||||
echo 服务已停止...
|
||||
pause
|
||||
exit
|
||||
|
||||
:restart
|
||||
taskkill /f /t /im PPGo_Job.exe
|
||||
start "PPGo_Job" /min PPGo_Job.exe
|
||||
echo 服务已重启...
|
||||
pause
|
||||
exit
|
||||
|
Before Width: | Height: | Size: 332 KiB |
|
Before Width: | Height: | Size: 369 KiB |
|
Before Width: | Height: | Size: 249 KiB |
|
Before Width: | Height: | Size: 260 KiB |
|
Before Width: | Height: | Size: 309 KiB |
|
Before Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 277 KiB |
|
Before Width: | Height: | Size: 354 KiB |
|
Before Width: | Height: | Size: 256 KiB |
|
Before Width: | Height: | Size: 292 KiB |
|
Before Width: | Height: | Size: 244 KiB |
|
Before Width: | Height: | Size: 261 KiB |
|
Before Width: | Height: | Size: 268 KiB |
|
Before Width: | Height: | Size: 227 KiB |
|
Before Width: | Height: | Size: 252 KiB |
|
Before Width: | Height: | Size: 266 KiB |