网络会时常断电,UPS不带通讯端口,无法和系统完成通讯功能.
使用PORTS安装fping程序,使用crontab几分钟调用下此程序,如发现网络不通,自动关机.
*Written By linyin
*Homepage:linyin.8800.org
#include
#include
#include
int main()
{
int a;
a=0;
system("/usr/local/sbin/fping -a ");
sleep(2);
struct stat buf;
stat("/root/fping",&buf);
while(a==buf.st_size)
{
sleep(5);
system("/usr/local/sbin/fping -a ");
sleep(2);
stat("/root/fping",&buf);
while(a==buf.st_size)
{
sleep(5);
system("/usr/local/sbin/fping -a ");
sleep(2);
stat("/root/fping",&buf);
while(a==buf.st_size)
{
sleep(5);
system("/usr/local/sbin/fping -a ");
sleep(2);
stat("/root/fping",&buf);
while(a==buf.st_size)
system("/sbin/shutdown -p now");
}
}
}
return 0;
}
阅读(1346) | 评论(0) | 转发(0) |