Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

shell script background job

Posted on 2004-11-10
7
Medium Priority
?
574 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:starfield
  • 3
5 Comments
 
LVL 16

Accepted Solution

by:
manav_mathur earned 252 total points
ID: 12542936
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
 

Author Comment

by:starfield
ID: 12543202
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 248 total points
ID: 12548512
I'd also quote the arguments:

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

0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 12552759

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

Manav
0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 12553403
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question