[plug] problem with script
James Devenish
devenish at guild.uwa.edu.au
Mon Aug 25 19:33:35 WST 2003
In message <sf4a6313.088 at mmtnetworks.com.au>
on Mon, Aug 25, 2003 at 07:26:59PM +0800, Jon Miller wrote:
> I'm now getting:
> # ./postfixstatchk.sh
> ./postfixstatchk.sh: line 54: syntax error: unexpected end of file
[...]
> Line 54 is the last line of the script and it ends with a "fi" which
> is part of a "if" statement.
I cannot find line 54 in the latest version of the script you sent.
> Correct me if I'm wrong, but using the following does generate a value
> of the variable by using ` `. What I was getting was 8-10 PID
> listings. Because I only require 1 listing I then added the following
> to the script:
> MMSTAT=`pgrep -u root mmsmtp.out`
> function fmlstat()
> {
> vMMSTAT="echo $MMSTAT | awk '{print $1}"
> echo $vMMSTAT
> }
1/ If you have multiple lines and only want the first line, use `head
-1`. For instance: `echo $MMSTAT | head -1`. This will give you the
first line of the standard output. Using `awk '{print $1}'` will print
the first *column* of *every* line. BTW `tail` is the counterpart to
`head`.
2/ You don't really need pgrep's output at all. If I understand your
usage correctly, you simply want to know whether there are any
mmsmtp.out processes. So all you need is the return code of pgrep, not
its textual output. Thus you can pgrep directly in your 'if' clause like
this:
if pgrep -u root mmsmtp.out >/dev/null; then
echo We have mmsmtp.out running
else
echo There is no active mmsmtp.out
fi
Or, for maximum clarity in your specific script:
MMSMTP_IS_RUNNING="pgrep -u root mmsmtp.out"
$MMSMTP_IS_RUNNING >/dev/null || mmpf
More information about the plug
mailing list