# ********************************************************** # * iWASQL -- utility to run SQL commands * # * and put the result in IFS or by mail * # * for many format files like * # * PDF, XLS, XML, CSV, ODS, SVG... * # * * # * * # * Patrick THOMAS, January 2009 * # * * # * mail-to : patrick30.thomas@laposte.net * # * * # ********************************************************** # go to the user directory cd ~ # Retreive the USER name from the JOBNAME user="$(echo $JOBNAME | sed 's/.*\/\(.*\)\/.*/\1/')" # Set the directory where is the template and the Template name TemplateDir="/qibm/userdata/Access/Web2/intappsvr/Admin/users/$user/db/requests/" # Set the jarfile to default : iWATask.jar iWATask="iWATask.jar" # process the options option_v=off option_s=off option_t=off option_j=off option_p=off while getopts vs:t:p:j: argname do case $argname in v) option_v=on;; s) option_s=on;source=$OPTARG;; t) option_t=on;target=$OPTARG;; j) option_j=on;jarfile=$OPTARG;; p) option_p=on;password=$OPTARG;; \?) print -u2 "Usage: ${0#$PWD/} [-s source] [-t target] [-p password] [-j Jar File] [-v] parameters"; exit 1;; esac done # get rid of options shift $OPTIND-1 # Test if the template is specified if [ -n "$source" ] then else echo the source file name was not specified exit 1 fi # Test if the template exists Template=$TemplateDir$source if !(test -e $Template) then echo "ERROR - Unknow source file : $Template" exit 1 fi # if no name of the jar file is specified, the name is the same as the source file if [ -n "$jarfile" ] then jarfile=$source.jar fi # Test if the password is specified if test $option_p = "on" then # it's necessary to create a new jar file from the original but under wich name ? # the name is specifed behind the option -j ? if test $option_j = "on" then if [ -n "$jarfile" ] then else jarfile=$source.jar fi else jarfile=$source.jar.tmp delete=on fi cp /QIBM/ProdData/Access/Web2/lib/$iWATask $jarfile # if no password, password = user if [ -n "$password" ] then else password=$user fi fi if !(test -e $jarfile) then echo "ERROR - Unknow Jar file : $jarfile" exit 1 fi # if no target the have the same name of the source file but in the current directory. # but it's necessary to retreive the output file type in the template. if [ -n "$target" ] then else target="$(sed -n '/fileName=/p' $Template)" target=${target:19:10} target=$source.$target fi # Create the temporary file propriety touch -C 819 task.properties echo "url=http://$HOSTNAME:2020/webaccess/iWADbExec" > task.properties echo "user=$user" >> task.properties echo "password=$password" >> task.properties echo "parm.request=$source.tmp" >> task.properties echo "output=$target" >> task.properties # if no jar file specified, put the proprietes file into the jar file if test $option_p = "on" then jar -uf $jarfile task.properties fi #for the remaining parameters #replace the parameters into the SQL statement cp $Template $Template.tmp if test $option_v = "on" then echo "----------------- replacement parameters -----------------" > SubstituteParameters.tmp if ( test $# -gt 0 ) then sed -n '/\[[0-9]/p' $Template.tmp >> SubstituteParameters.tmp fi fi i=0 while ( test $# -gt 0 ) ; do let i+=1 # Replacement of the special character by an apostrophe param="$(echo "$1" | sed 's/#/'\''/g')" # If verbose, save the information about replacement strings if test $option_v = "on" then echo "Replacement parameter [${i}] by : $param" >> SubstituteParameters.tmp fi sed -e "s/\[${i}\]/$param/g" $Template.tmp > $Template.tmp1 shift rm $Template.tmp touch -C 819 $Template.tmp cat $Template.tmp1 > $Template.tmp done # process the job if test $option_v = "on" then echo echo "************************ START ************************" cat SubstituteParameters.tmp echo "------------------- Template prorieties -------------------" cat $Template.tmp java -jar -Dcom.ibm.as400.webaccess.iWATask.log.category=all $jarfile cat iWATask.log echo "************************ END ************************" rm SubstituteParameters.tmp else java -jar $jarfile fi # Delete the temporary jar file if test $delete = "on" then rm $jarfile fi # remove the temporary file propriety rm $Template.tmp* #done exit 0