Execute a shell script from within a C-Program - Unix

This is a discussion on Execute a shell script from within a C-Program - Unix ; Hello Group, I want to execute a shell-script from within a c-program. It should run on a solaris 10 host and work as a cgi-application. But when I run it I get a core-dump. Is this a "you can not ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Execute a shell script from within a C-Program

  1. Execute a shell script from within a C-Program

    Hello Group,
    I want to execute a shell-script from within a c-program.
    It should run on a solaris 10 host and work as a cgi-application.
    But when I run it I get a core-dump.
    Is this a "you can not to it this way" or have I forgotten something?
    Thank you for any hints.

    Bernhard


    I do it the following way (c-wrapper application):
    //----------------------
    #include
    #include
    int main(void)
    {
    int c;
    FILE *in_stream;
    system("/export/home/buchreit/snmp_scripts/snmpwalk_GetARPTable
    192.168.10.1");
    printf("Content-type: text/html\n\n"); //HTML-Header
    in_stream =
    fopen("/export/home/buchreit/snmp_scripts/ARPTable","r");
    while ((c=fgetc(in_stream)) != EOF)
    printf("%c",c);

    return(0);
    }
    //----------------------------
    The shell-script looks like:
    //-----------------------------
    snmpwalk -c public -v 1 $1 1.3.6.1.2.1.4.22.1.2 > tmp_ARPtable
    sed -f cmd.sed tmp_ARPtable > ARPtable
    //------------------------------
    And the sed-command-file looks like:
    //-------------------------------
    s/^IP-MIB\:\:ipNetToMediaPhysAddress\./\\/
    s/ = STRING\: /\<\/td\>\/
    s/$/\<\/td\>\<\/tr\>/
    //-------------------------------



  2. Re: Execute a shell script from within a C-Program

    none wrote:

    > Hello Group,
    > I want to execute a shell-script from within a c-program.
    > It should run on a solaris 10 host and work as a cgi-application.
    > But when I run it I get a core-dump.
    > Is this a "you can not to it this way" or have I forgotten something?
    > Thank you for any hints.
    >
    > Bernhard
    >
    >
    > I do it the following way (c-wrapper application):
    > //----------------------
    > #include
    > #include
    > int main(void)
    > {
    > int c;
    > FILE *in_stream;
    > system("/export/home/buchreit/snmp_scripts/snmpwalk_GetARPTable
    > 192.168.10.1");
    > printf("Content-type: text/html\n\n"); //HTML-Header
    > in_stream =
    > fopen("/export/home/buchreit/snmp_scripts/ARPTable","r");
    > while ((c=fgetc(in_stream)) != EOF)
    > printf("%c",c);
    >
    > return(0);
    > }
    > //----------------------------
    > The shell-script looks like:
    > //-----------------------------
    > snmpwalk -c public -v 1 $1 1.3.6.1.2.1.4.22.1.2 > tmp_ARPtable
    > sed -f cmd.sed tmp_ARPtable > ARPtable
    > //------------------------------
    > And the sed-command-file looks like:
    > //-------------------------------
    > s/^IP-MIB\:\:ipNetToMediaPhysAddress\./\\/
    > s/ = STRING\: /\<\/td\>\/
    > s/$/\<\/td\>\<\/tr\>/
    > //-------------------------------


    did you try running the script by itself? not from the C program?
    next, try running the script form your C prog, but have the script just echo
    the $1 param and exit. Whats the script bash? might put #!/bin/bash at the
    top but probably that wont matter, your script is called like this:
    /bin/sh -c /export/home/buchreit/snmp_scripts/snmpwalk_GetARPTable
    192.168.10.1
    according to the man page i have.
    Beyond that, i dont see anything in your system command that looks illegal.
    Eric




  3. Re: Execute a shell script from within a C-Program


    "Eric" schrieb im Newsbeitrag
    news:BKKdnTys6YusNkHfRVn-jg@comcast.com...

    > did you try running the script by itself? not from the C program?
    > next, try running the script form your C prog, but have the script just
    > echo
    > the $1 param and exit. Whats the script bash? might put #!/bin/bash at the
    > top but probably that wont matter, your script is called like this:
    > /bin/sh -c /export/home/buchreit/snmp_scripts/snmpwalk_GetARPTable
    > 192.168.10.1
    > according to the man page i have.
    > Beyond that, i dont see anything in your system command that looks
    > illegal.
    > Eric
    >


    Thank you for your answer.
    The script by itself works. Inserting th #!/usr/bin/bash line into the
    shell-script does not change the core-dumping of the C-program.
    Very strange...

    Bernhard



  4. Re: Execute a shell script from within a C-Program

    As almost ever it is a OSI-layer 8 problem :-)
    It was a typo - I've tried to open a file that does not exist.
    (ARPTable versus ARPtable)

    Sorry for asking the group before looking exactly ...

    Friendly Greetings to anyone who has to work in summer ;-)

    Bernhard



+ Reply to Thread