• Status: Solved
  • Priority: High
  • Security: Private
  • Views: 195
  • Last Modified:

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
0
Pradeep0308
Asked:
Pradeep0308
  • 2
  • 2
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now