Professional Web Applications Themes

Execute a shell script from within a C-Program - Linux / Unix Administration

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 <stdio.h> #include <stdlib.h> 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

    Default 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 <stdio.h>
    #include <stdlib.h>
    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\./\<tr\>\<td\>/
    s/ = STRING\: /\<\/td\>\<td\>/
    s/$/\<\/td\>\<\/tr\>/
    //-------------------------------


    none Guest

  2. #2

    Default Re: Execute a shell script from within a C-Program

    none wrote:
     

    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



    Eric Guest

  3. #3

    Default Re: Execute a shell script from within a C-Program


    "Eric" <org> schrieb im Newsbeitrag
    news:com...
     

    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


    none Guest

  4. #4

    Default 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


    none Guest

Similar Threads

  1. WScript.Shell to execute Ms-DOS commands?
    By news.microsoft.com in forum ASP
    Replies: 2
    Last Post: December 8th, 06:49 PM
  2. Replies: 1
    Last Post: November 7th, 07:40 PM
  3. Execute shell script from a perl script
    By kderaedt in forum Perl / CGI
    Replies: 3
    Last Post: June 26th, 08:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139