Script issue - Prints pages with jibberish...

Hi all,

I have a script from a programmer, for which I need to analyze a problem.

The script gathers audit info and prints out the results. Two different departments use it, on two different printers. In the script department the there are no issues. In the other department the same script produces "problem" pages among the normal pages. They are either blank, or full of random collection of characters.

I need to put some kind of echo statements around the print functions and redirect it to a sort of error_show.txt file, so that we can see what is happening. We presume it is due to the usage of different printers.

If we can visualize the errors we can see if it is a problem with printer type or settings or whatnot.

This is the code

#!/usr/bin/sh
 export PATH=/usr/bin:${PATH}
 PRINTER="system"  
 ERRFILE=$(mktemp -c)
 while getopts d: optchar; do
 case $optchar in
 d)
 PRINTER=$OPTARG;;
 esac
 done
 if [ -z "${PRINT_SERVER_HOME}" ]; then
 [[ -f `cat /etc/PRINT_SERVER_HOME`/custom/etc/setup_env.sh ]] && . `cat /etc/PRINT_SERVER_HOME`/custom/etc/setup_env.sh
 fi
 if [ -z "${PRINT_SERVER_HOME}" ]; then
 echo "Unable to setup PRINT_SERVER environment"
 echo "Exitting..."
 exit 1
 fi
 cd /var/spool/edi/ebill/audits
 # We would like to print Audit files for AVAL
 # if file aval.lst existed then delete it
 if [ -e aval.lst ]; then
 rm aval.lst
 fi
 # if avalaudt3.* exists then execute ll command below
 if [ -e avalaudt3.* ]; then
 ll avalaudt3.*>>aval.lst
 fi
 AVALFILELIST=$(gfind . -type f -name "avalaudt3.???" | sort -t'.' +2 )
 AVALNEWFILELIST=""
 for AVALFILE in ${AVALFILELIST}; do
 if [ -s ${AVALFILE} ]; then
 AVALNEWFILELIST="${AVALNEWFILELIST} $(pwd)/${AVALFILE##./}"
 fi
 done
 # if file aval.lst exists and not empty
 if [ -s aval.lst ]; then
 ${PRINT_SERVER_HOME}/bin/pdpr -d${PRINTER} -x"-start-sheet none" ${AVALNEWFILELIST} >${ERRFILE} 2>&1
 fi
 if [ $? -ne 0 ]; then
 echo "ERROR: pdpr command failed for file aval.lst" >&2
 cat ${ERRFILE} >&2
 fi
 rm -f ${ERRFILE} 2>/dev/null
 

I have highlighted the print function. Any help would be appreciated. The programmer inherited the script an doesn't want to delve too deeply into it.

I, however, would like to figure out what is happening and not waste the paper. However, this kind of script is way above my head, as of right now.

The problem may just be the avalaudt3.* input files generated there. It is a bit odd to juggle two lists, one from ll and one from gfind !

1 Like

Thanks,

I had the script fixed up a bit...

However getting an error when I'm trying to echo the print function to a file.

Here is the code:

#!/usr/bin/sh
 #put /usr/bin in the path first. This is for security
 export PATH=/usr/bin:${PATH}
 #Get the Output Server environment variables in
 if [ -z "${Print_Server_HOME}" ]; then
 [[ -f `cat /etc/Print_Server_HOME`/custom/etc/setup_env.sh ]] && . `cat /etc/Print_Server_HOME`/custom/etc/setup_env.sh
 fi
 if [ -z "${Print_Server_HOME}" ]; then
 echo "Unable to setup Print_Server environment"
 echo "Exitting..."
 exit 1
 fi
 #Script Variables
 PRINTER="system"  
 ERRFILE=$(mktemp -c)
 DIR="/var/spool/edi/ebill/audits"
 #parse command line arguments
 while getopts d: optchar; do
 case $optchar in
 d)
 PRINTER=${OPTARG};;
 esac
 done
 ###############################################################
 # Main Program
 ###############################################################
 cd ${DIR}
 #if [ $? -ne 0 -o $(pwd) != ${DIR} ]; then do
 if [ $? -ne 0 -o $(pwd) != ${DIR} ]; then
 exit 1
 fi
 # We would like to print Audit files for AVAL
 # if file aval.lst existed then delete it
 [[ -f aval.lst ]] && rm aval.lst
 #if [ -f aval.lst ]; then
 # rm aval.lst
 #fi
 # if avalaudt3.* exists then execute ll command below
 #if [ -e avalaudt3.* ]; then
 # ll avalaudt3.*>>aval.lst
 #fi
 #AVALFILELIST=$(gfind . -maxdepth 1 -type f -name "avalaudt3.???" | sort -t'.' +2 )
 #AVALNEWFILELIST=""
 #for AVALFILE in $(cat ${AVALFILELIST}); do
 #for AVALFILE in $(gfind . -maxdepth 1 -type f -name "avalaudt3.???" -size +0 | sort -t'.' +2); do
 # #if [ -s ${AVALFILE} ]; then
 # AVALNEWFILELIST="${AVALNEWFILELIST} $(pwd)/${AVALFILE##./}"
 # #fi
 #done
 AVALNEWFILELIST=$(gfind . -maxdepth 1 -type f -name "avalaudt3.???" -size +0 | sort -t'.' +2)
 echo ${AVALNEWFILELIST} | xargs -i ll -d "{}" >aval.lst 2>&1
 # if file aval.lst exists and not empty
 if [ -s aval.lst ]; then
 echo "AVALNEWFILELIST: ${AVALNEWFILELIST}" >> {"/home/user1/bin/outfile.out"} 2>&1
 #pdpr -d${PRINTER} -x"-start-sheet none" ${AVALNEWFILELIST} >${ERRFILE} 2>&1
 #${Print_Server_HOME}/bin/pdpr -d${PRINTER} -x"-start-sheet none" ${AVALNEWFILELIST} >${ERRFILE} 2>&1
 RET=$?
 fi
 ###############################################################
 ###############################################################
 ###############################################################
 ###############################################################
 ###############################################################
 #Testing
 ###############################################################
 ###############################################################
 ###############################################################
 ###############################################################
 ###############################################################
 exit 0
 ###############################################################
 if [ ${RET} -ne 0 ]; then
 echo "ERROR: pdpr command failed for file aval.lst" >&2
 cat ${ERRFILE} >&2
 fi
 [[ -f ${ERRFILE} ]] && rm -f ${ERRFILE} 2>/dev/null
 

Getting a:

I must have put something wrong in the redirect section of the echo statement.

Why are you using

{"/home/user1/bin/outfile.out"}

Just put filename alone without braces and ".

1 Like

Thank you. I figured that out.

Do you have write permission for the output?

1 Like

Yes, I'm using root so no problem there. I think the problem is in the different printers. Something is going on there.

I was able to get the echo statement and output and it still prints out weird pages.

Getting a fresh set of files tomorrow. Will see what happens...

Printers are called through Output Server...

A shot in tge dark: do the departments each have their own printer ? It might be that each printer expects a different encoding.

Going back to the original code...

 ${PRINT_SERVER_HOME}/bin/pdpr -d${PRINTER} -x"-start-sheet none" ${AVALNEWFILELIST} >${ERRFILE} 2>&1

According to the online docs for this command, the printer is specified with

-p${PRINTER}

and not "-d". For a number of reasons this could be the source of your problem

Mmmm,

We're using HP's Output Server. And that is a custom pdpr command made by our boss. Works off of the command line, however it fails when used within a script.

If I use the syntax for pdpr on the command line, and list files like: /home/user/filelist.a* it will print without the random characters in between.

I think we're close to figuring it out.

"custom pdpr made by our boss" just sunk in. Great! He can figure the problem
out then since it's probably a bug in his program.

It can also be one o your files includes a control character that sets the printers output mode to something else.

Have you tried printing to the opposing printer? Might eliminate the printer itself.
What is the make and model of each printer, and how are they connected to the network? Do they both have the same amount of internal memory?

Is this custom "pdpr" an alias, a script or what? Has $PATH been modified to find a different version when used from the command line? i.e. Are you sure that you are executing the same program from your script?

Slightly off topic (I think): Beware that $PRINTER is a system reserved Environment Variable name left over from early unix but still read by modern commands. It's usually mentioned in "man lp" to name but a few places.

The HP "Advance Printing Software" product is well documented for Tru64 unix, but would help to know what Operating System and version you have.