Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116015
  • 博文数量: 20
  • 博客积分: 1430
  • 博客等级: 上尉
  • 技术积分: 215
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-16 07:08
文章分类

全部博文(20)

文章存档

2011年(1)

2010年(1)

2009年(8)

2008年(10)

我的朋友

分类: BSD

2008-09-16 07:34:51

网络会时常断电,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;
}
阅读(1306) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~