Ad Widget

Collapse

zabbix_get with crontab script doesn't make output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arifzulfikar
    Junior Member
    • Mar 2014
    • 7

    #1

    zabbix_get with crontab script doesn't make output

    Hi Zabbix Expert,

    I'm currently develop some script to get some value with "bash scripting"
    My script is like below :

    #!/bin/bash
    ##START OF SCRIPT
    filenow=$(date --date="now" +"cpu_""%d%m%y-%H""00")
    dir=/home/local/zabbixresearch/logreport/cpu

    CPU_TEST()
    {
    echo "TEST_SERVER" >> $dir/$filenow.txt
    app1_cpu=`zabbix_get -s 192.168.0.22 -k "system.cpu.util[,system,avg1]" | awk -F '.' '{print $1}'`
    if [ $app1_cpu -lt 90 ];
    then
    echo "OK" >> $dir/$filenow.txt
    elif [ $app1_cpu -gt 90 ];
    then
    echo "NOK" >> $dir/$filenow.txt
    else
    echo "NOT VALUE" >> $dir/$filenow.txt
    fi
    }

    CPU_TEST

    ##ENDOFSCRIPT

    when I running this from the screen it produce output like below :
    [local@local cpu]$ /home/local/zabbixresearch/script/cpu.sh

    It produce output like I expected in the .txt file
    [local@local cpu]$ cat /home/local/zabbixresearch/logreport/cpu
    TEST_SERVER
    OK

    But when I using crontab it always produce NOT VALUE.
    [local@local cpu]$ cat /home/local/zabbixresearch/logreport/cpu
    TEST_SERVER
    NOT VALUE

    I dont know why this is happen, is that because zabbix_get command cannot use by crontab or this is problem with some permission?

    my crontab is like below (with user local):

    [local@local cpu]$ crontab -l
    0 */1 * * * /home/local/zabbixresearch/script/cpu.sh

    Any ideas with it?

    Regards,
    Arif
  • aib
    Senior Member
    • Jan 2014
    • 1615

    #2
    try to use the full path in your script, like
    Code:
    /usr/bin/zabbix_get .....
    Sincerely yours,
    Aleksey

    Comment

    • arifzulfikar
      Junior Member
      • Mar 2014
      • 7

      #3
      [SOLVED] zabbix_get with crontab script doesn't make output

      Bro Aleksey,

      Thanks, its work

      I change my script variable to be :
      app1_cpu=`/usr/local/bin/zabbix_get -s 192.168.0.22 -k "system.cpu.util[,system,avg1]" | awk -F '.' '{print $1}'`

      Best Regards from Indonesia

      Arif

      Comment

      Working...