filePro/email from Unix script file

Fairlight fairlite at fairlite.com
Wed Dec 14 13:51:10 PST 2005


The honourable and venerable Butch Ammon spoke thus:
>
> But... what happens when the filePro report runs and doesn't happen to
> select any records?  The script file continues and emails a blank report!
>
> Is there a quick way to kill the script file when the records selected is
> "0"?
>
> example:
> -------------------------------------------------------------------------
> #/usr/bin/partscheck - Butch 5/2/02 # /u/appl/fp/dreport purchase -f
> partscheck -s partscheck -u -p /tmp/partscheck mail -s "parts check
> report" kari at rich.srcoils.com < /tmp/partscheck mail -s "parts check
> report" linda at rich.srcoils.com < /tmp/partscheck
> -------------------------------------------------------------------------
[snip]
> But again, what happens if there are no records selected?  The report
> will still run, and create a blank /tmp file report and email it anyway.

Is it -really- blank, as in a 0 byte long file?  If so, try:

-------------------------------------------------------------------------
#!/bin/csh
# /usr/bin/partscheck - Butch 5/2/02 
# Fairlight mod 12/14/05 for 0-byte length check
# 
set length=`wc -c /tmp/partscheck |awk '{print $1}'`
if (${length} != 0) then
     /u/appl/fp/dreport purchase -f partscheck -s partscheck -u -p /tmp/partscheck 
     mail -s "parts check report" kari at rich.srcoils.com linda at rich.srcoils.com < /tmp/partscheck 
endif
exit
-------------------------------------------------------------------------

Please note that if you're doing this with concurrent users, you're
entirely subject to a race condition unless you start using unique file
names and passing them along to the script.

Sorry I flipped to csh.  My Bourne is way rusty and I knew I could at least
get the csh syntax correct on the first go.  At least I didn't give you
something that required you to install perl. :)

I also combined your mail commands into one that just has multiple
recipients.  You shouldn't need two commands unless your `mail` program is
-really- broken, or you want to only list one recipient at a time.  You
could just as easily use the original two commands.

You get bonus points for not redundantly using `cat` though!  :)  I'm
impressed, seriously.

Bests,

mark->


More information about the Filepro-list mailing list