Unix ksh script

Hi All,

I have a directory full of specific file types with extension as .txt. I would like to specify the directory as an argument and want to loop through each one of the .txt file and run a particular command against this .txt file for example below:

#${JAVA} -Dvendor=shell -DvendorFile=${INSTALL_DIR}/properties/servers.properties com.addWorkflow -s -U -d "Added using command line Mass Add" -f 1.txt

I would then want the output of above command to be added to a report. If there is an error then report should be appended for all errors. The script should loop through each file and perform the above action and log in case of any errors with filename specified so its clear which error belongs to which txt file.

Thanks for your help.

Regards
Pradeep
Pradeep0308Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Try something like this:


#!/bin/ksh

JAVA="##your definition here##"
INSTALL_DIR="##your definition here##"
REPORTFILE="/path/to/reportfile"
ERRORFILE="/path/to/errorfile"
INPUTDIR=$1

for file in ${INPUTDIR}/*.txt
  do
     ${JAVA} -Dvendor=shell -DvendorFile=${INSTALL_DIR}/properties/servers.properties com.addWorkflow -s -U -d "Added using command line Mass Add" -f $file >>$REPORTFILE 2>err.tmp
     if [[ -s err.tmp ]]; then
         echo $file $(cat err.tmp) >> $ERRORFILE
     fi
  done


Bolded items must be customized by you!  

Assuming you named the above "myscript" run it like this:
myscript "/path/to/dir/containing/txtfiles"
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pradeep0308Author Commented:
Didnt work. Resulted in below error:

Error creating a file, the wildcard provided resulted in an empty file list...
java.lang.NullPointerException
0
Pradeep0308Author Commented:
#!/bin/ksh

INSTALL_DIR="/application/node1"
REPORTFILE="/application/node1/report"
ERRORFILE="/application/node1/report"
INPUTDIR=$1

for file in ${INPUTDIR}/*.txt
  do
     ${JAVA} -Dvendor=shell -DvendorFile=${INSTALL_DIR}/servers.properties -classpath ${INSTALL_DIR}/jar/bootstrapper.jar com.NoAppLoader -f ${INSTALL_DIR}/dynamicclasspath.cfg -class com.addWorkflow  -invokeargs "-s" "-U" "-d" "Added using command line Mass Add" "-f" $file >>$REPORTFILE 2>err.tmp
     if [[ -s err.tmp ]]; then
         echo $file $(cat err.tmp) >> $ERRORFILE
     fi
  done

Gives below error:

Cannot write to a directory.
imported.sh[10]: /application/node1/report: 0403-005 Cannot create the specified file.
Cannot write to a directory.
imported.sh[10]: /application/node1/report: 0403-005 Cannot create the specified file.
0
woolmilkporcCommented:
You don't have write access to the specified output directory. Choose a different one for the output files.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.