LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 657|回复: 0

提供给高手们看看,请问我在linux如何让一台windows电脑关机

[复制链接]
发表于 2005-1-10 20:08:20 | 显示全部楼层 |阅读模式
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <syslog.h>
#include <string.h>
#include <paths.h>

#ifndef SIGPWR

#  define SIGPWR SIGUSR1
#endif

#define PWRSTAT         "/etc/powerstatus"

/* Tell init that the power has gone (1), is back (0),
   or the UPS batteries are low (2). */
void powerfail(int event)
{
  int fd;

/* Create an info file for init. */
unlink (PWRSTAT);
if ((fd = open(PWRSTAT, O_CREAT|O_WRONLY, 0644)) >= 0) {
switch (event)
      {
      case 0 :
              write(fd, "OK\n", 3);
              break;

      case 1:
             write(fd, "WAIT\n", 5);
             break;
      case 2:
      default:
             write(fd, "FAIL\n", 4);
             break;
      }
  close(fd);
  }
  kill(1, SIGPWR);
}

/* Main program. */
int main(int argc, char *argv[])
{
int DCD;

if (argc < 2) {
       fprintf(stderr, "Usage: turn [0|1]\n");
       exit(1);
}/* Start syslog. */
openlog("turn", LOG_CONS, LOG_DAEMON);

DCD = atoi(argv[1]);
if(DCD != 0) powerfail(0); else powerfail(1);
}

以上是在192.168.7.112上的
turn.c程式
gcc turn.c -o turn


以下是/etc/inittab中的几行
pf::powerfail:/sbin/shutdown -f -h +30 "ower Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "ower Restored; Shutdown Cancelled"


在有电源检测的服务器上
shd
/usr/bin/ssh root@192.168.7.112 /root/turn 0
/sbin/shutdown -f -h +30 "ower Failure; System Shutting Down"

备注:可以用ssh给别人发送执行命令。。。
shc
/usr/bin/ssh root@192.168.7.112 /root/turn 1
/sbin/shutdown -c "ower Restored; Shutdown Cancelled"

当然服务器上有如些一服务在运行。。见
powerd.c
这一套是公司的一个牛人做的。。。硬件我就不懂了。。。用RSA232与电脑联接。。
还有是一个非UPS上的220V-->。。。设备很小。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表