How do I know if a system has powered on?

2019-03-27 07:48发布

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.

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 ].

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条回答
老娘就宠你
2楼-- · 2019-03-27 08:19

I think checking for sshd sounds like a good approach.

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.

查看更多
迷人小祖宗
3楼-- · 2019-03-27 08:21

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

查看更多
来,给爷笑一个
4楼-- · 2019-03-27 08:23

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.

查看更多
男人必须洒脱
5楼-- · 2019-03-27 08:27

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).

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.

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.

查看更多
登录 后发表回答