The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script errors?

Discussion in 'cPanel Developers' started by ARWEB, Feb 17, 2011.

  1. ARWEB

    ARWEB Member

    Joined:
    Jul 19, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    I want to know why if I make a script with .sh type and run it by ssh and works ok without errors, why if I put it in crontab give me errors?
    checarga.sh: line 7: service: command not found
    checarga.sh: line 8: service: command not found


    This is my script checarga.sh:
    #!/bin/bash
    #
    carga=$(cut -f1 -d' ' /proc/loadavg)
    carga=$(echo $carga | bc | sed 's/[.].*//')

    if [ $carga -gt 15 ]; then
    service mysql restart
    service crond restart
    fi

    Could somebody help me? Thank you very much.
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Did you put it into root crontab? A user likely cannot run such a script and it would require root level access to do it.
     
  3. ARWEB

    ARWEB Member

    Joined:
    Jul 19, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Of course Tristan, I do all with root user by SSH, so???
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    If this is in /var/spool/cron/root file as a root user cron and returning that error, then try the following in the script instead for lines 7 and 8:

    Code:
    /etc/init.d/mysql restart
    /etc/init.d/crond restart
     
  5. ARWEB

    ARWEB Member

    Joined:
    Jul 19, 2007
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Thank you Tristan, script's working now.

    Have a nice day and God bless you.
     
Loading...

Share This Page