[plug] problem with script
Jon Miller
jlmiller at mmtnetworks.com.au
Mon Aug 25 20:52:56 WST 2003
Jon L. Miller, MCNE, CNS
Director/Sr Systems Consultant
MMT Networks Pty Ltd
http://www.mmtnetworks.com.au
"I don't know the key to success, but the key to failure
is trying to please everybody." -Bill Cosby
>>> devenish at guild.uwa.edu.au 7:33:35 PM 25/08/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.
jlm> it's the last line
> 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`.
jlm> output from running following command:
MLSTAT=`pgrep -U postfix`
gateway:~# echo $MLSTAT | head -1
2118 3100 3137
This is why I use the awk command to get the first column of information.
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.
jlm> yes I need to know if there are any processes running, but this process has anywhere between 1-12 processes running so I only need the results to list one.
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:
jlm> I'll give this a go and see how it works.
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
jlm> I think if this can give me a 0 or 1 then it'll be what I need, but instead all I'm able to get is a PID number.
More information about the plug
mailing list