procmail
[Top] [All Lists]

Re: Variable greater/less than testing

2009-08-24 21:01:27

----- "Stephen Allen" <sdaprocmail(_at_)rowyerboat(_dot_)com> wrote:
         maxValue=256000

         :0
         * $     ${foo:+!}
         {
                 foo=${maxValue}
      }

At the moment, if 'foo' isn't set or is set, but null, it gets
assigned 
  $maxValue.  Now let's say foo is set to "foobar", I would need to 
recognise it's not a number (perhaps -eq 0), and then like before, 
assign it $maxValue.


You're probably better off using scoring.  For example, I use this
(posted a little while ago to the list) to make sure that the system
load is under 10 when trying to perform certain high-CPU usage recipes.

   # LOADAVG is integer value of load average, MAXIMUM is load threshold
   LOADAVG=`cat /proc/loadavg | sed 's/\..*//'`
   MAXIMUM=10

   # Set SCORE to MAXIMUM - LOADAVG
   :0
   *$ -$LOADAVG ^0
   *$  $MAXIMUM ^0
   { }
   SCORE=$=

   # Was the score negative?  If so, exit immediately telling sendmail
   # to requeue, load average was too high
   :0
   * $ SCORE ?? ^^-
   {
      EXITCODE=75
      HOST="_load_average_too_high_"
   }

You could also use test, but it's more expensive for your server
(something I wanted to avoid in a high load average test):

   LOADAVG=`cat /proc/loadavg | sed 's/\..*//'`
   MAXIMUM=10

   :0
   *$ ? test $LOADAVG -gt $MAXIMUM
   {
      EXITCODE=75
      HOST="_load_average_too_high_"
   }

Chris
____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>