Execute a shell script from within a C-Program
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Execute a shell script from within a C-Program




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Execute a shell script from within a C-Program  
none


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-19-05 07:48 AM

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\>/
//-------------------------------







[ Post a follow-up to this message ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-19-05 12:49 PM


"Eric" <BorgMotherShip@AliensR_US.org> 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







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:46 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register