[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell programming



"Jeremy C. Reed" <reed@wcug.wwu.edu> writes:

> Does anyone know how I can combine a pipe with an "&&"?

I doubt it can be done with a "&&".

> I have a script that mails some piped input, but I don't want it to
> mail if no has no data.
> 
> Is there a command for exiting if no stdin, but if there is just
> pipe it through?

Hmmmm, do you mean like "... | stdintest | mail ....".  This won't
work since the shell will have already started the mail process.

Why not redirect the output to a file and then test if the file
contains any output:

	#!/bin/sh
	
	LOGFILE=/var/named/logs/logfile
	MAILTO=jcr@iwbc.net
	SUBJECT="dns problems report"
	
	grep `date +"%d-%b-%Y"` $LOGFILE | \
	  egrep 'reject|failed|error' | \
	  cut -f 3-100 -d " " | \
	  sort | \
	  uniq > /tmp/$$.out
	
	if [ -s /tmp/$$.out ]; then
	  mail -s "$SUBJECT" $MAILTO < /tmp/$$.out
	fi
	rm /tmp/$$.out

Hope this helps.

Cheers,
Roland.
-- 
Tell me and I'll forget; show me and I may remember;
involve me and I'll understand - Chinese Proverb.


Reply to: