shell script background job

Can anyone help me with this script? I want to work so that if the user enters P (for printer) then it runs as a background job and returns the user back the menu screen. When it runs, it shows a blank screen and nothing can be done until the report has finished. This is a problem because users think the report isn't running, try to quit and run it again etc etc . Here is the script, I know its lengthy but I'd appreciate any help anyone can give me on this matter.

runname=`cat $REP_USER_PATH/srepuser`
trap "" 0 1 2

check_error ()
{
     if grep -q "ORA-" $1
      then
        echo "\nReport GDS024 failed to complete."
        echo "Report $*"
        grep -e "ORA-" -e "PLS" -e "ERROR" $1
        rm $1
        rm $2
        sleep 3
        exit 1
      fi
}

SQLNAME=r1GDScpurp.sql
DIRPATH=$HOME/a$2

cat <<! > /tmp/p$2
$DIRPATH
$3
8
!
if [ $1 = S ]
   then
echo `tput clear`
echo "\n\n\n        Generating Report - GDS024     Please wait.....\c"
(echo "\n Started Report "$2" On "`date`
sqlplus -s $runname @$SQLNAME< /tmp/p$2
wait $!
check_error $DIRPATH /tmp/p$2
sed "s/^??//" $DIRPATH > $HOME/$2
echo "Report: $* "
echo "\n Report Ended "$2" On "`date` ) 1>>$HOME/log.`date +%d%m` 2>&1
wait $!
scanrep $HOME/$2
if [ -f /tmp/$2 ]
   then rm /tmp/$2
fi
else
(echo "\n Started Report "$2" On "`date`
sqlplus -s $runname @$SQLNAME< /tmp/p$2
wait $!
check_error $DIRPATH /tmp/p$2
sed "s/^??//" $DIRPATH > $HOME/$2
echo "Report: $* "
if [ $1 = P ]
   then lp -d$DEFPRT $HOME/$2
if [ -f /tmp/$2 ]
   then rm /tmp/$2
fi
fi ) 1>>$HOME/log.`date +%d%m` 2>&1 &
fi
wait $!
if [ -f $DIRPATH ]
   then rm $DIRPATH
fi
if [ -f $HOME/$2 ]
   then
      repsz=`cat $HOME/$2|wc -l`
      ( sqlplus -s $runname @reportsz $2 $repsz ) 1>>$HOME/log.`date +%d%m` 2>&1
    else
      echo "Report $2 has failed to complete \c"
      sleep 5
fi

trap 0 1 2
starfieldAsked:
Who is Participating?
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.

manav_mathurCommented:
Try doin this.
if [ $1 = P ]
   then (lp -d$DEFPRT $HOME/$2 2 > lperror.log) &

The extra lperror.log is so that any error message from the lp doesnt get
on the screen. (and spoil your menu)

Manav
0

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
starfieldAuthor Commented:
Thanks I will try this, I don't think there are any errors though as the report prints off fine. It just doesn't revert back to the menu screen while its running.

0
ahoffmannCommented:
I'd also quote the arguments:

if [ "$1" = 'P' ];

0
manav_mathurCommented:

I'd agree with ahoffman. 'twill save your if from flunking "under adverse circumstances"

Manav
0
manav_mathurCommented:
Starfield,

I haven't used lp so I dont the program behaviour.
But what if the printer's not ready(out of paper).

These are general errors with printers.

IMHO, you should maintain an error log.

Manav
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
System Programming

From novice to tech pro — start learning today.

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.