i am writing a pogram where i have to find out which all computers are up on my lan...for this i have called shell script program from my C code which pings to all computers on lan....now i want the shell script to return to the C code "1" incase the computer is up...how do i do that...
i=$(ping $1 -c 2 | grep -c "ttl=")
if [ $i -eq 2 ]
then echo host is reachable
else echo host is not reachable
fi
my C code
int main()
{
int fd,i,j,flag;
char *fname,member[40],ch,str[40];
fd = open("/etc/members",O_RDONLY);
if(fd == -1) printf("Members info can not be retrived.");
ch = 0; flag = 0;
while(read(fd,&ch,1))
{
i = 0;
while(1)
{
if(ch == '\t') break;
member[i++]=ch;
read(fd,&ch,1);
}
member[i]='\0';
strcpy(str,"./shscrpt ");
strcat(str,member);
j=system(str);
printf("%d",j);
while(read(fd,&ch,1)) if(ch == '\n') break;
}
return 0;
}
thanks in advance