Shell script stops working

SHANLEY at MAINE.BITNET SHANLEY at MAINE.BITNET
Sat Mar 24 00:51:12 AEST 1990


System:    AT&T 3B2-400
           Unix V 3.0
           4 Meg Ram
           72 Meg Hard Disk
           286 Meg Hard Disk
           C language Issue 3.1 11/19/85
           Bourne Shell
 
 
    I wrote a c program that accesses the curses library and produces a
menu on the terminal. Users select the number of of the menu item they wish
to execute.  The c program uses the system () command to execute a shell
script that acts as an interface to other programs so I don't have to keep
recompiling the c program.  I have enclosed the appropriate portions of
both the c program and the shell scripts.
 
 
Senerio:  The uses selects the FinalBilling choice of the menu selection.
          The c program executes the system () and access the shell script.
          The shell script executes an numberinp.x to input the work order
          numbers that are to be billed.  Once these numbers are entered,
          the users goes back to the c program and the shell script calls
          itself again and goes on its merry way to do the billing.
 
 
Problem:  The senerio works great for awhile but then suddenly the shell
          script won't do the billing.
 
           nohup menu.s Billout final $inpfile 1>$errfile &
 
          It won't execute ... menu.s Billout ....  I know it executes
          the nohup because it produces the file $errfile but it doesn't
          execute the rest of the command menu.s Billout ...
 
          I thought I might have a problem with recursively calling
          shell scripts so I put the Billout) portion of the shell script
          in a shell file and called it.  Didn't work.
 
            nohup billout.s ... &
 
 
          It seems like I am accumlating a counter in some system variable
          that reaches its limit and refuses to decrement to a lower value
          once the shell script has finished executing.
 
          I have reason to believe that I have too many open files and that
          the OS is not acknowledging the fact that I am done with the files.
 
          To get to the menu program, the processes look like:
 
           PID TTY      TIME COMMAND
          1456 console  0:03 sh
          1467 console  0:04 dbmenu
          1468 console  0:00 sh
          1469 console  0:01 sh
          1470 console  0:41 menu.x
 
          Am I using up 3 files for each "sh" above? (ie stdin, stdout,
          and stderr)
 
          Any thoughts?  ideas?
          Am I on the right track?
 
 
 
 
menu.c :
/* Execute the billing menu */
 
void
billing (c)
 
char c;
 
{
 
 
  /* Choose a menu option */
  switch (c) {
 
 
    case  '1':  menuhelp ("Batches", 0);
                prtmenu  ("Billing");
                break;
 
    case  '2':  menuhelp ("FinalBilling", 0);
                prtmenu  ("Billing");
                break;
 
    case  '3':  menuhelp ("PartialBilling", 0);
                prtmenu  ("Billing");
                break;
 
    case  '4':  menuhelp ("MonthlyBilling", 0);
                prtmenu  ("Billing");
                break;
 
    case 'cn':  prtmenu ("Worksys");
                break;
 
    default  :  break;
 
 
  }  /* Choose a menu option */
 
 
}  /*  Execute the billing menu */
 
 
 
 
 
/* Execute the menu.s program */
 
void
menuhelp (program, getcopy)
 
char *program;
long getcopy;
 
{
 
char copies, *reportname[80+1], *command[80+1];
 
 
  /* Get the report copies */
  if (getcopy == 1)
  {
 
    strcpy (reportname, program);
    strcat (reportname, " Report");
 
    prtmenu (reportname);
    copies = getch ();
 
    move (10, 34);
 
  }  /* Get the report copies */
 
 
  attron  (A_STANDOUT);
  addstr  ("  Executing  ");
  attroff (A_STANDOUT);
  refresh ();
  endwin  ();
 
  sprintf (command, "menu.s %s %c", program, copies);
  system  (command);
 
  initscr ();
  cbreak  ();
  raw     ();
 
 
}  /* Execute the menu.s program */
 
 
menu.s:
 
 
# Select a worksys function
case $1 in
 
 
  # Billing
 
    FinalBilling)
 
      inpfile=/usr/tmp/billinp.$$
      numberinp.x FinalBilling 1 2>$inpfile
 
      if test -s $inpfile
      then
          errfile=../bill/`acego -q batchnum`.error
 
#  Problem line
         nohup menu.s Billout final $inpfile 1>$errfile &
 
      fi
 
      rm -f $inpfile
 
      ;;
 
 
    Billout)
 
      billtype=$1
 
      echo "cncncncncn"
      echo "Do you want to print the bills? (Y/N)  :  cc"; read prtbill
      batch=`sort -u /usr/tmp/billinp.$$ | billing.x`
      mv $2 ../bill/$batch.input
 
      sort -u ../bill/$batch.input |
 
      while
        read work
      do
 
        # Print new page
        case $newpage in
          1) echo "cf" ;;
          *) newpage=1 ;;
        esac
        # Print new page
 
        echo "cncncncncn"      > /usr/tmp/billout.$$
        acego -q revlab $work >> /usr/tmp/billout.$$
        labor=`tail -1 /usr/tmp/billout.$$`
        labor=`echo $labor | awk '{printf ("%s", $4)}'`
 
        echo "cncncncncn"     >> /usr/tmp/billout.$$
        acego -q revsup $work >> /usr/tmp/billout.$$
        supply=`tail -1 /usr/tmp/billout.$$`
        supply=`echo $supply | awk '{printf ("%s", $2)}'`
 
        acego -q billcust $billtype $work $labor $supply
        cat /usr/tmp/billout.$$
 
        acego -q batchlab $work >> /usr/tmp/billbat.$$
        acego -q batchsup $work >> /usr/tmp/billbat.$$
 
      done > ../bill/$batch.output
 
 
      cut -c43-59 /usr/tmp/billbat.$$ |
        batch.x $batch `date +%m%d` > ../bill/$batch.batch
      cat /usr/tmp/billbat.$$ >> ../bill/$batch.batch
 
 
      cat ../bill/$batch.batch  | lp -c -d$PRINTER -s 2>/dev/null
      cat ../bill/$batch.error  | lp -c -d$PRINTER -s 2>/dev/null
 
      # Print the bills
      case $prtbill in
 
        Y)  cat ../bill/$batch.output | lp -c -d$PRINTER -s 2>/dev/null
            ;;
 
        y)  cat ../bill/$batch.output | lp -c -d$PRINTER -s 2>/dev/null
            ;;
 
        *)  ;;
 
      esac  # Print the bills
 
 
      input=../bill/$batch.input
 
      # Archive the work order
      case $billtype in
 
        final)  cat $input | archiver.x work     arcwork     00/00/00 00/00/00
                cat $input | archiver.x estimate arcestimate 00/00/00 00/00/00
                ;;
 
            *)  ;;
 
      esac  # Archive the work order
 
      cat $input | archiver.x labor    arclabor    00/00/00 00/00/00
      cat $input | archiver.x supply   arcsupply   00/00/00 00/00/00
 
      rm /usr/tmp/billout.$$
      rm /usr/tmp/billbat.$$
 
      ;;
 
 
      rm $2
 
esac
 



More information about the Comp.unix.wizards mailing list