Need simple help in editing my cronjob

Discussion in 'Site & Server Administration' started by Hipto, Sep 23, 2009.

  1. #1
    Guys the below is what I'm using now. It restarts httpd under stated condition. Is it possible to make it stop httpd and start again ONLY after certain timeframe like 15 minutes? Thanks for help

    #!/bin/bash
    loadavg=`uptime | awk '{print $10}'`
    RESTART="/etc/init.d/httpd restart"
    thisloadavg=`echo $loadavg|awk -F \. '{print $1}'`
    if [ "$thisloadavg" -ge "400" ]; then
    echo "restarting due to load being $thisloadavg"
    $RESTART
    elif [ "$thisloadavg" -le "400" ]; then
    echo Not restarting, load is $thisloadavg
    if [ $? -ne 0 ]
    then
    $RESTART
    fi
    fi
    Code (markup):
     
    Hipto, Sep 23, 2009 IP
  2. zacharooni

    zacharooni Well-Known Member

    Messages:
    346
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    120
    #2
    400 seems a bit high to setting load caps at.

    Might try something like this:

    
    #!/bin/bash
    MAX="15"
    LOAD="`uptime | awk '{print $10}' | sed -e 's/\,//'`"
    if [ "$LOAD" -gt "$MAX" ]; then
      echo "Current Load: $LOAD - Restarting HTTPD"
      /sbin/service httpd stop
      sleep 5
      /sbin/service httpd start
    fi
    
    Code (markup):
    You also may want to tweak Apache a little bit, let me know if you need some help.
     
    zacharooni, Sep 24, 2009 IP
  3. thuankkk

    thuankkk Active Member

    Messages:
    503
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    95
    #3
    To stop after 15 minutes, you can use
    
    sleep 900
    
    Code (markup):
    However, turn off httpd due to high server load is not recommended.

    You'd better try to optimize apache and your script.
     
    thuankkk, Oct 22, 2009 IP