[Top][All Lists]

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

Scripting question

From: Martinez, Michael
Subject: Scripting question
Date: Mon, 24 Nov 2003 15:45:40 -0500

Guys - 

If there's a more appropriate mailing list for this question, let me

I'm trying to solve a scripting issue, preferably using the shell
without using sed, awk, or such tools. Qmail comes with a program called
qmail-remote that always returns with exit code 0. Its standard output
is a series of reports, usually two or three. Each report beings with a
single letter that signifies a success or error code. The possible
letter values are r h s K Z D. Each report consists of characters that
are terminated with a 0-byte. I need to be able to grab the
single-letter code from each report and generate an exit code based on
the combination of codes. There are three possible exit codes: 0
(success), 100 (permanent failure) or 111 (temporary failure). For
example, if the codes are h and D, then this is a permanent failure. The
standard output from qmail-remote needs to pass through unaltered. 

The main problem I encountered is dealing with the 0-byte at the end of
each report. The following shell code works because it generates an exit
code based only on the very first letter in the qmail-remote stdout,
discards the qmail-remote stdout and generates its own standard output.
If we stick a while loop in here to read each line, it will choke on the
0-byte characters:

Qmail-remote | { IFS='' read -r i; retcode="${i:0:1}"; echo "$retcode:
qmail-remote return code"; case "$retcode" in r|K) exit 0; ;; h|D) exit
100; ;; *) exit 111; ;; esac; }

Anyone got any suggestions?

Michael Martinez
United States Department of Agriculture
This email is signed with my digital signature so that you may verify
the authenticity of the sender.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]