Ad Widget

Collapse

Script user parameters can't pass to shellscript and return segment fault core dumped

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mtpumpkin
    Junior Member
    • Jul 2018
    • 9

    #1

    Script user parameters can't pass to shellscript and return segment fault core dumped

    My script in C to make a send sms file:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #pragma GCC diagnostic ignored "-Wwrite-strings"

    void process(char v1[], char v2[], char v3[]){

    FILE *fp1;
    fp1 = fopen("sms_script.sh", "w+");
    fprintf(fp1,"count=$( cat countmess)\ncount=$((count+1))\n");
    fprintf(fp1,"sshpass -p "12345678" ssh -o StrictHostKeyChecking=no [email protected] sudo mmcli -m 1 --messaging-create-sms="text=\'%s-%s\',number=\'%s\'"\n",v2,v3,v1);
    fprintf(fp1,"sshpass -p "12345678" ssh -o StrictHostKeyChecking=no [email protected] sudo mmcli -s $count --send exit\n");
    fprintf(fp1,"rm -f countmess\necho "$count" >> countmess\nexit");
    fclose(fp1);
    system("./sms_script.sh");
    return;
    }

    int main(int argc, char *argv[]){
    process(argv[1],argv[2],argv[3]);
    return 0;
    }
    ==========================
    My run.sh file to receive parameter from zabbix then pass it to script above:

    #!/bin/bash
    /usr/lib/zabbix/alertscripts/editScript $1 $2 $3
    =========================
    2 files above are put in: "/usr/lib/zabbix/alertscripts/" with full x+ permission
    then I go to to Admin => Media Type and create new:

    then I go to tab user and config user media:


    but when trigger on, zabbix throw the error that "segment fault. core dumped at run.sh line 2: "/usr/lib/zabbix/alertscripts/editScript $1 $2 $3"

    I change to use remote command in action => operation with fixed phone number and macros {HOST.NAME} and {TRIGGER.NAME} but zabbix return "killed by signal 11"

    - Anyone have solutions for that?
    - How to choose and send parameters to shellscript?
    Last edited by mtpumpkin; 12-07-2018, 04:11.
  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    \Just take generated core file and using gdb (gdb-c <core>") and try to locate where it crashes.
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    • mtpumpkin
      Junior Member
      • Jul 2018
      • 9

      #3
      Originally posted by kloczek
      \Just take generated core file and using gdb (gdb-c <core>") and try to locate where it crashes.
      I use SSH and call the script all OK without error. But when zabbix call the script then it throw error

      Comment

      • kloczek
        Senior Member
        • Jun 2006
        • 1771

        #4
        Originally posted by mtpumpkin

        I use SSH and call the script all OK without error. But when zabbix call the script then it throw error
        Did you done diagnostics using core file?
        http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
        https://kloczek.wordpress.com/
        zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
        My zabbix templates https://github.com/kloczek/zabbix-templates

        Comment

        Working...