Ad Widget

Collapse

User external script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mhustak
    Junior Member
    • Apr 2020
    • 4

    #1

    User external script

    HI all.

    I have some strange problem with external script.

    If I run script localy on server script finished correcly.

    PROCESS_NAME=$1;
    typeset -i PROCESS_MEM;
    PROCESS_MEM=0;

    ########################
    # FUNCTION SCRIPT PART #
    ########################

    ####################
    # MAIN SCRIPT PART #
    ####################

    process_all_pid=$(ps -ef | grep "${PROCESS_NAME}" | grep -Ev 'ksh|grep' | awk '{print $2}');
    RC=$?;
    echo $process_all_pid
    if [ $RC -eq 0 ]; then
    for process_pid in $process_all_pid; do
    if [ $process_pid -ne 0 ]; then
    process_memory_usage=$(eval /usr/bin/svmon -P ${process_pid} -O summary=basic,unit=KB | awk '/^[0-9]/ {print $NF}');
    ((PROCESS_MEM=PROCESS_MEM + $process_memory_usage));
    fi;
    done;
    else
    echo "0";
    exit 0;
    fi;

    echo $PROCESS_MEM
    #echo $process_memory_usage
    #echo $process_pid

    exit 0;

    If I run on server all work fine.

    /usr/sbin/externalscripts/proc_mem_usage.ksh unica_aclsnr
    11599902
    255548

    but if I run the same script from zabbix server over agent a take this

    11599902
    /usr/sbin/externalscripts/proc_mem_usage.ksh[42]: PROCESS_MEM=PROCESS_MEM + ***: syntax error

    Its very funny, how I can get diferent output from same script?
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    Does your script start with
    Code:
    #! [I]/path/to/the/shell/interpreter[/I]
    ?

    You may want to do some web searching for the terms "Linux shbang" or "Linux script sh-bang" or "shell script magic number" to understand what the sh-bang line does for your script and why you should always include it.

    Comment

    • mhustak
      Junior Member
      • Apr 2020
      • 4

      #3
      Here is all script include interpreter

      #!/usr/bin/ksh

      ################################################## ################################################## ##############################
      #
      # Popis :
      #
      ################################################## ################################################## ##############################
      #
      # File :
      # Version : $Revision: 0.01.001 $
      # Date : $Date: 2016/08/15 11:00:00 $
      # Author :
      #
      ################################################## ################################################## ##############################
      #
      # 0.1 Initial alpha version
      #
      ################################################## ################################################## ##############################

      ########################
      # VARIABLE SCRIPT PART #
      ########################
      PROCESS_NAME=$1;
      typeset -i PROCESS_MEM;
      PROCESS_MEM=0;

      ########################
      # FUNCTION SCRIPT PART #
      ########################

      ####################
      # MAIN SCRIPT PART #
      ####################

      process_all_pid=$(ps -ef | grep "${PROCESS_NAME}" | grep -Ev 'ksh|grep' | awk '{print $2}');
      RC=$?;
      echo $process_all_pid
      if [ $RC -eq 0 ]; then
      for process_pid in $process_all_pid; do
      if [ $process_pid -ne 0 ]; then
      process_memory_usage=$(eval /usr/bin/svmon -P ${process_pid} -O summary=basic,unit=KB | awk '/^[0-9]/ {print $NF}');
      ((PROCESS_MEM=PROCESS_MEM + $process_memory_usage));
      fi;
      done;
      else
      echo "0";
      exit 0;
      fi;

      echo $PROCESS_MEM
      #echo $process_memory_usage
      #echo $process_pid

      exit 0;

      Comment

      • tim.mooney
        Senior Member
        • Dec 2012
        • 1427

        #4
        If the problem is not that the script is being run by a different shell interpreter, then I would expect that the next most likely issue is a permission issue. Are you certain that the "eval /usr/bin/svmon" ... code can be successfully executed by a process running as the 'zabbix' user?

        You probably will eventually want to remove or comment out the "echo $process_all_pid", since your script (when working) probably should only be returning one value, but I don't think that's what's causing the issue you're seeing.

        Comment

        • mhustak
          Junior Member
          • Apr 2020
          • 4

          #5
          Ok now I change script.


          #!/usr/bin/ksh

          ################################################## ################################################## ##############################
          #
          # Popis :
          #
          ################################################## ################################################## ##############################
          #
          # File :
          # Version : $Revision: 0.01.001 $
          # Date : $Date: 2016/08/15 11:00:00 $
          # Author :
          #
          ################################################## ################################################## ##############################
          #
          # 0.1 Initial alpha version
          #
          ################################################## ################################################## ##############################

          ########################
          # VARIABLE SCRIPT PART #
          ########################
          PROCESS_NAME=$1;
          typeset -i PROCESS_MEM;
          PROCESS_MEM=0;

          ########################
          # FUNCTION SCRIPT PART #
          ########################

          ####################
          # MAIN SCRIPT PART #
          ####################

          process_all_pid=$(ps -ef | grep "${PROCESS_NAME}" | grep -Ev 'ksh|grep' | awk '{print $2}');
          RC=$?;
          if [ $RC -eq 0 ]; then
          for process_pid in $process_all_pid; do
          if [ $process_pid -ne 0 ]; then
          #process_memory_usage=$(/usr/bin/svmon -P 11599902 -O summary=basic,unit=KB);
          process_memory_usage=$(/usr/bin/svmon -P 11599902 -O summary=basic,unit=KB | awk '/^[0-9]/ {print $NF}');
          #process_memory_usage=$(eval /usr/bin/svmon -P ${process_pid} -O summary=basic,unit=KB | awk '/^[0-9]/ {print $NF}');
          # ((PROCESS_MEM=PROCESS_MEM + $process_memory_usage));
          fi;
          done;
          else
          echo "0";
          exit 0;
          fi;

          #echo $PROCESS_MEM
          echo $process_memory_usage
          #echo $process_pid

          exit 0;

          But it's the same.

          If I run script directly on the server I take this.

          /usr/sbin/externalscripts/proc_mem_usage.ksh unica_aclsnr
          292864 <- this is value of memmory usage

          If I run the same script from zabbix server I take this.

          Value of type "string" is not suitable for value type "Numeric (float)".
          Value "admin aplikace audit bin bosinst.data dev etc home image.data lib lost+found lpp mnt nsr opt proc root runclisamp.aix32 runclisamp.aix64 sbin scratch smit.log smit.script smit.transaction sysbackup teradata tftpboot tmp u unix usr var".

          Comment

          Working...