#include
#include
#include
#include
#include
int checkethn(char *netcard)
{
FILE *fp;
char buf[200]={0};
if((fp = popen(netcard,"r"))!=NULL)
while(fgets(buf, 200, fp)!= NULL)
{
if (strstr(buf,"Link detected: yes")!=NULL)
{
return(1);
break;
}
}
pclose(fp);
return(0);
}
int main()
{
int errno;
printf("UPS Stop,Auto ShutDown\n");
daemon(0,0);
while(1)
{
errno=checkethn("ethtool eth0");
if(errno==0)
{
sleep(30);
errno=checkethn("ethtool eth0");
if(errno==0)
system("poweroff");//printf("poweroff\n");
}
sleep(90);
}
}