[comp.unix.xenix] Supress Error Message

mel@fleet.UUCP (mel) (11/23/89)

I'm using the following "C" script to check for the presence of unsent
mail etc under Xenix 386 ver 2.3.1. 

#! /bin/csh
#
# call only on demand
#
foreach i (rex cbay)
    foreach j (/usr/spool/uucp/$i/C.$i*)
        if (-e $j) then
            /usr/lib/uucp/uucico -r1 -s$i
        endif
        break
    end
end


The above script is triggered by the following line in my root cron file.

0,15,30,45  * * * *     csh /usr/lib/uucp/uucall >/dev/null

Whenever either the directories the script is checking for are empty
and/or erased by uuclean an error message like the following is sent to
the root user. (These keep filling up my root mail file every 15 minutes.)

*************************************************
Cron: The previous message is the standard output
      and standard error of one of your cron commands.

From root Thu Nov 16 18:15:01 1989
To: root
Date: Thu Nov 16 18:15:00 1989
foreach: No match.


HOW CAN I ALTER THIS SCRIPT TO AVOID THE SENDING OF THIS MESSAGE FOR BOTH
OF THE TWO CASES STATED ABOVE?

Thanks in advance,

Mel Shear
!rex!mgse!fleet!mel

tale@pawl.rpi.edu (David C Lawrence) (11/24/89)

In <52@fleet.UUCP> mel@fleet.UUCP (mel) writes:
Mel> #! /bin/csh
Mel> foreach i (rex cbay)
Mel>     foreach j (/usr/spool/uucp/$i/C.$i*)
Mel>         if (-e $j) then
Mel>             /usr/lib/uucp/uucico -r1 -s$i
Mel>         endif
Mel>         break
Mel>     end
Mel> end

Mel> The above script is triggered by the following line in my root cron file.
Mel> 0,15,30,45  * * * *     csh /usr/lib/uucp/uucall >/dev/null

Why are you doing it this way?  Does your XENIX not understand #! execution?
If it does you shouldn't need the "csh".

Mel> foreach: No match.

Yeah.  C Shell globbing does that to you.

Mel> HOW CAN I ALTER THIS SCRIPT TO AVOID THE SENDING OF THIS MESSAGE FOR BOTH
Mel> OF THE TWO CASES STATED ABOVE?

A FEW DIFFERENT WAYS.  Oops, looks like the ol' caps lock got stuck.

You could rewrite it in sh; pretty trivial for this.  In fact, just
change everything to the equivalent Bourne shell syntax and your
problem goes away:

#! /bin/sh
for i in rex cbay; do
  for j in /usr/spool/uucp/$i/C.$i*; do
    if [ -s $j ]; then # okay, okay.  not really same as -e
      /usr/lib/uucp/uucico -r1 -s$i
      break 2  # okay, so i moved the break too.  Why was a foreach even used?
    fi
  done
done

But that's more a political statement against csh than anything else,
so just "set nonomatch" at the head of your csh script and the same
sort of processing would occur.

If you want to just bag any error messages that ever might happen, you
could redirect stderr from the cron invocation, too.

You could also use find(1) to avoid globbing complaints; take out the
foreach j and replace it with:

  if [ "`find /usr/spool/uucp/$i -name \"C.$i*\" -print`" ]; then
     uucico ...
  fi

There are probably at least four or five other ways to work this out,
including a perl solution from Randall, soon to be appearing in a
comp.unix.* group near you.

Dave
-- 
 (setq mail '("tale@pawl.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))

merlyn@iwarp.intel.com (Randal Schwartz) (11/29/89)

In article <256C6EAA.736E@rpi.edu>, tale@pawl (David C Lawrence) writes:
| There are probably at least four or five other ways to work this out,
| including a perl solution from Randall, soon to be appearing in a
| comp.unix.* group near you.

I wasn't going to do a Perl one this time, Dave, but since you botched
the spelling of my name (or my Mom did, one of the two... :-), here it
is...

#!/usr/bin/perl
for $i (("rex","cbay")) {
	@a = </usr/spool/uucp/$i/C.$i*>;
	next unless -e $a[0];
	system "/usr/lib/uucp/uucico","-r1","-s$i";
}

There.  Neat and clean.

Just another Perl hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/