2010年4月22日木曜日

用linux执行Crontab时,调用Java jar文件时候乱码

环境准备:
cat /etc/crontab

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

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

# ToppanForms File Server Manager, file operation rules
30 10 * * * root /usr/local/helios/var/authsrv/doFileOperation.sh 4
-------------------------------------------------------------------------------------------
cat doFileOperation.sh

#!/bin/sh
cd /usr/local/helios/var/authsrv
/usr/java/jdk1.6.0_18/bin/java -Xbootclasspath/a:mysql-connector-java-5.1.7- bin.jar:proxool-0.9.1.jar:spring2.5.5.jar:proxool-cglib.jar:commons-logging- 1.1.1.jar -jar /usr/local/helios/var/authsrv/doFileOperation.jar -id $1
-------------------------------------------------------------------------------------------
产生原因:crontab执行linux脚本时,不会携带系统编码,需要手工指定。

解决方案:
①查看系统编码
# cat /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
-------------------------------------------------------------------------------------------
②编辑Linux脚本文件,指定编码类型
#vim doFileOperation.sh

#!/bin/sh
export LANG="ja_JP.UTF-8"
cd /usr/local/helios/var/authsrv
/usr/java/jdk1.6.0_18/bin/java -Xbootclasspath/a:mysql-connector-java-5.1.7- bin.jar:proxool-0.9.1.jar:spring2.5.5.jar:proxool-cglib.jar:commons-logging- 1.1.1.jar -jar /usr/local/helios/var/authsrv/doFileOperation.jar -id $1
-------------------------------------------------------------------------------------------

0 件のコメント: