linux下小程序部署

1、应用场景

使用java project写了一个小程序,需要部署在linux下自动定时执行

java工程目录:

linux下部署的结构

2、shell脚本

#!/bin/bash

BIN_PATH=/usr/local/work/timertask
EXE_NAMe=com.hu.demo.MonthSettle
RUN_NAME=run_monthsettle.sh


CLASSPATH=$CLASSPATH:.:${BIN_PATH}/
for file in ${BIN_PATH}/lib/*;
do CLASSPATH=${CLASSPATH}:$file;
done

export CLASSPATH
echo $CLASSPATH

if [ -z $1 ]
then 
abc=`date -d last-month "+%Y-%m"`
else 
abc=$1
fi
if [-z $2]
then
carrier_code=''
else
carrier_code=$2
fi

echo $abc
echo $carrier_code

/usr/java/jre/bin/java $EXE_NAMe $abc $carrier_code

3、配置对应的linux下的crontab 定时任务

(1)、crontab -e 编辑crontab,crontab -l 查看crontab


SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
#*/8 * * * * /usr/local/work/collection/run.sh >> /usr/local/work/collection/log.log

猜你喜欢

转载自blog.csdn.net/u011768625/article/details/81477409