07-19-05 07:48 AM
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 <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\>/
> //-------------------------------
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
[ Post a follow-up to this message ]
|