#!/bin/bash
echo "----------------Java调用shell脚本执行客户端加解密任务,开始--------------------------"
pwdDir=`pwd`
cd $pwdDir
echo "当前工程目录:"$pwdDir
#查找数据库文件并读取数据
db_properties=`find $pwdDir -name "db.properties"`
if [ -f "$db_properties" ];then
#db_type=$(cat "$db_properties" | grep "dbType" | awk -F '=' '{print $2}')
db_user=$(cat "$db_properties" | grep "userName" | awk -F '=' '{print $2}')
db_pwd=$(cat "$db_properties" | grep "passWord" | awk -F '=' '{print $2}')
echo "userName=$db_user" > client.conf
echo "passWord=$db_pwd" >> client.conf
tr -d '\r' < client.conf > client.txt
fi
db_user=$(cat client.txt | grep "user" | awk -F '=' '{print $2}')
db_pwd=$(cat client.txt | grep "passWord" | awk -F '=' '{print $2}')
echo $db_user
echo $db_pwd
client_installDir=`find /opt -name "AOEClient_auto"`
cd $client_installDir/processor
echo "进入processor目录:"$client_installDir/processor
jarfile=`ls *.jar`
echo $jarfile
if [ -z "$jarfile" ];then
echo "不存在jar包"
exit 1
fi
source /etc/profile
echo "java -jar $jarfile --op=batchUpdate --user=$db_user --password=$db_pwd --taskId=$1 --threads=4"
echo $db_user
echo $db_pwd
java -jar $jarfile --op=batchUpdate --user=$db_user --password=$db_pwd --taskId=$1 --threads=4
echo "----------------Java调用shell脚本执行客户端加解密任务,结束--------------------------"
优化后脚本:
#!/bin/bash
echo "----------------Java调用shell脚本执行客户端加解密任务,开始--------------------------"
pwdDir=`pwd`
cd $pwdDir
echo "当前工程目录:"$pwdDir
#查找数据库文件并读取数据
db_properties=`find $pwdDir -name "db.properties"`
if [ -f "$db_properties" ];then
user=$(cat "$db_properties" | grep "userName" | awk -F '=' '{print $2}')
password=$(cat "$db_properties" | grep "passWord" | awk -F '=' '{print $2}')
client_installDir=`find /opt -name "AOEClient_auto"`
cd $client_installDir/processor
echo "进入processor目录:"$client_installDir/processor
jarfile=`ls *.jar`
echo $jarfile
if [ -z "$jarfile" ];then
echo "不存在jar包"
exit 1
fi
source /etc/profile
echo "java -jar $jarfile --op=batchUpdate --user=$user --password=$password --taskId=$1 --threads=4"
java -jar $jarfile --op=batchUpdate --user=$user --password=$password --taskId=$1 --threads=4
fi
echo "----------------Java调用shell脚本执行客户端加解密任务,结束--------------------------"
备注:需要修改配置文件为unix格式,并且编码改成(UTF-8)