简体   繁体   中英

bash file looping and passing contents to java call

I have the following bash script and it isn't quite working right. The objective here is to move XMLs from /source to /active folders, then call a java script and pass in XML file contents as argument, then move active file from /active to /archive folder.

Any help is greatly appreciated!

#!/bin/bash 
JAVA_HOME=/usr/lib/jvm/jdk1.6.0_02 
CLASSPATH=/tracking/lib/tracking_client.jar: .
FILES=/tracking/source/*
for f in $FILES
do
  filename=$(basename "$f")
  cd /tracking/source/
  mv /tracking/source/${filename} /tracking/active/${filename}
  cd /tracking/active/
  $JAVA_HOME/bin/java -cp $CLASSPATH TrackClient  ## need to pass XML file contents in to java call as argument
  mv /tracking/active/${filename} /tracking/archive/${filename}
done
exit 0

使用$()将命令结果插入命令中。

$JAVA_HOME/bin/java -cp $CLASSPATH TrackClient  "$(cat "/tracking/active/${filename}")"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM