我如何知道系统是否已启动?

时间:2022-12-24 07:31:07

I am writing a script that powers on a system via network. And then i need to run a few commands on the other host. How do I know whether the system has powered on?

我正在编写一个通过网络启动系统的脚本。然后我需要在另一台主机上运行一些命令。我如何知道系统是否已开机?

My programming language is Perl and the target host is RHEL5.

我的编程语言是Perl,目标主机是RHEL5。

Is there any kernel interrupt or network boot information that indicates the system has powered on and the os has loaded?

是否存在任何内核中断或网络引导信息,表明系统已启动且操作系统已加载?

[In a different scenario] I was also wondering just in case if i just switch on my Machine manually. when is it exactly said to have powered on. and when is the OS is supposed to have booted completely for a network related operation such as executing a network command there. What if the system is on DHCP how would a remote system then search for this machine [i guess it is possible via mac address. but if i am wrong ].

[在另一种情况下]我也想知道以防万一我只是手动打开我的机器。什么时候它确实说是打开电源。何时OS应该完全启动以进行网络相关操作,例如在那里执行网络命令。如果系统在DHCP上怎么办远程系统然后搜索这台机器怎么办[我想可以通过mac地址。但如果我错了]。

If I have missed out any info please feel free to ask me. If you have any suggestions to make the task easier please surface them :)

如果我错过了任何信息,请随时问我。如果您有任何建议可以让任务更容易,请表明他们:)

thanx imkin

4 个解决方案

#1


12  

Well, I'd say the system is booted when it can perform the request you've made of it. That is, the sshd daemon is running. That's booted sufficiently for your purposes (I assume - substitute for whatever daemon you really need).

好吧,我会说系统在它可以执行你的请求时启动了。也就是说,sshd守护程序正在运行。这是为了你的目的足够启动(我假设 - 替换你真正需要的任何守护进程)。

So, I'd send the power-on signal, and check back every 15-30 seconds to see if I could connect. If I've failed to connect within whatever is a reasonable time for that machine (2 minutes or 5 minutes or whatever), then I'd send an alert to the IT support team. Well, I'd send it to myself first, and only once I've investigated a few failures or so and found them to all be legitimate would I start sending it directly to IT.

所以,我发送电源开启信号,每15-30秒检查一次,看看我是否可以连接。如果我无法在合理的时间内连接该机器(2分钟或5分钟或其他),那么我会向IT支持团队发送警报。好吧,我先把它发给自己,只有在我调查了几次失败之后才发现它们都是合法的,我会开始直接发送给它。

DHCP is kind of a different question. You'd have to start learning about broadcasting, or having a daemon on that machine "call home" during boot to register its current IP address. And it would have to "call home" every time a DHCP renewal changed its IP address. This is decidedly more convoluted. Try to avoid DHCP on such server machines if at all possible.

DHCP是一个不同的问题。你必须开始学习广播,或者在启动过程中在该机器上有一个守护进程“回家”以注册其当前的IP地址。每次DHCP续订改变其IP地址时,它都必须“回家”。这显然更复杂。尽可能避免在这样的服务器上使用DHCP。

#2


9  

On the rebooting machine you can install a script in your crontab with the special @reboot assertion (see man 5 crontab). That script could send a notification of some kind to the other machine, notifying it that it's up now.

在重新启动计算机上,您可以使用特殊的@reboot断言在crontab中安装脚本(请参阅man 5 crontab)。该脚本可以向另一台机器发送某种通知,通知它现在已经启动。

#3


7  

I think checking for sshd sounds like a good approach.

我认为检查sshd听起来是一个很好的方法。

As for the DHCP problem: if the other computer is on the same subnet you can look it up by MAC address using Net::ARP.

至于DHCP问题:如果另一台计算机在同一个子网上,您可以使用Net :: ARP通过MAC地址查找。

#4


3  

How about adding a script to the remote machine which gets run on startup to have it tell you when it is ready.

如何将脚本添加到远程计算机上,该计算机在启动时运行,让它在准备就绪时告诉您。

#1


12  

Well, I'd say the system is booted when it can perform the request you've made of it. That is, the sshd daemon is running. That's booted sufficiently for your purposes (I assume - substitute for whatever daemon you really need).

好吧,我会说系统在它可以执行你的请求时启动了。也就是说,sshd守护程序正在运行。这是为了你的目的足够启动(我假设 - 替换你真正需要的任何守护进程)。

So, I'd send the power-on signal, and check back every 15-30 seconds to see if I could connect. If I've failed to connect within whatever is a reasonable time for that machine (2 minutes or 5 minutes or whatever), then I'd send an alert to the IT support team. Well, I'd send it to myself first, and only once I've investigated a few failures or so and found them to all be legitimate would I start sending it directly to IT.

所以,我发送电源开启信号,每15-30秒检查一次,看看我是否可以连接。如果我无法在合理的时间内连接该机器(2分钟或5分钟或其他),那么我会向IT支持团队发送警报。好吧,我先把它发给自己,只有在我调查了几次失败之后才发现它们都是合法的,我会开始直接发送给它。

DHCP is kind of a different question. You'd have to start learning about broadcasting, or having a daemon on that machine "call home" during boot to register its current IP address. And it would have to "call home" every time a DHCP renewal changed its IP address. This is decidedly more convoluted. Try to avoid DHCP on such server machines if at all possible.

DHCP是一个不同的问题。你必须开始学习广播,或者在启动过程中在该机器上有一个守护进程“回家”以注册其当前的IP地址。每次DHCP续订改变其IP地址时,它都必须“回家”。这显然更复杂。尽可能避免在这样的服务器上使用DHCP。

#2


9  

On the rebooting machine you can install a script in your crontab with the special @reboot assertion (see man 5 crontab). That script could send a notification of some kind to the other machine, notifying it that it's up now.

在重新启动计算机上,您可以使用特殊的@reboot断言在crontab中安装脚本(请参阅man 5 crontab)。该脚本可以向另一台机器发送某种通知,通知它现在已经启动。

#3


7  

I think checking for sshd sounds like a good approach.

我认为检查sshd听起来是一个很好的方法。

As for the DHCP problem: if the other computer is on the same subnet you can look it up by MAC address using Net::ARP.

至于DHCP问题:如果另一台计算机在同一个子网上,您可以使用Net :: ARP通过MAC地址查找。

#4


3  

How about adding a script to the remote machine which gets run on startup to have it tell you when it is ready.

如何将脚本添加到远程计算机上,该计算机在启动时运行,让它在准备就绪时告诉您。