Hi,<br><br>From my file server I want to start the backup server by WOL, run the backup and then power it down.<br><br>I found the script below on the web and it works. However it comes with the warning "Be careful, you could corrupt valid entries if those NICs are already active". Does anyone have a better magic packet creating script which is fail safe?
<br><br>The next problem is powering down. When I run halt (slackware) the power is left on and the last line of output says Power Down. I need it to actually power down. The machine I am testing on is a Pentium II with an ATX power supply, so I assume it is capable of switching itself off. I tried halt -p but that made not difference. Any suggestions? I also tried apm -S and got the message "No apm support in the kernel", do I really need apm support in the kernel?
<br><br>#!/usr/bin/perl -w<br>#<br># Reads from stdin or a file lines of the form<br>#<br># <a href="http://12.34.56.78">12.34.56.78</a> aa:bb:cc:dd:ee;ff or<br># <a href="http://foo.bar.com">foo.bar.com</a> aa:bb:cc:dd:ee:ff
<br>#<br># which are hostname and MAC addresses of NICs to send a wakeup packet.<br>#<br># This program may have to be run with superuser privilege because it<br># may need to inject an ARP entry into the cache.<br># Be careful, you could corrupt valid entries if those NICs are
<br># already active.<br>#<br># Perl version by <a href="mailto:ken.yap@acm.org">ken.yap@acm.org</a> after DOS/Windows C version posted by<br># <a href="mailto:Steve_Marfisi@3com.com">Steve_Marfisi@3com.com</a> on the Netboot mailing list
<br># Released under GNU Public License, 2000-01-05<br>#<br>use Socket;<br><br>while (<>) {<br> ($ip, $mac) = split;<br> next if !defined($ip) or !defined($mac) or $ip eq '' or $mac eq '';<br> &send_wakeup_packet($ip, $mac);
<br>}<br><br>sub send_wakeup_packet {<br> ($ip, $mac) = @_;<br><br> if (!defined($iaddr = inet_aton($ip))) {<br> print "Cannot resolve $ip\n";<br> return;<br> }<br> if ($mac !~ /[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}:[\da-f]{2}/i) {
<br> print "Malformed MAC address $mac\n";<br> return;<br> }<br> # Inject entry into ARP table, in case it's not there already<br> system("arp -s $ip $mac") == 0<br> or print "Warning: arp command failed, you need to be root\n";
<br> # Remove colons<br> $mac =~ tr/://d;<br> # Magic packet is 6 bytes of FF followed by the MAC address 16 times<br> $magic = ("\xff" x 6) . (pack('H12', $mac) x 16);<br> # Create socket<br> socket(S, PF_INET, SOCK_DGRAM, getprotobyname('udp'))
<br> or die "socket $!\n";<br> # Send the wakeup packet<br> print "Sending wakeup packet to $ip at MAC address $mac\n";<br> defined(send(S, $magic, 0, sockaddr_in(0x2fff, $iaddr)))<br> or print "send: $!\n";
<br> close(S);<br>}<br><br>Perhaps we can have an evening devoted to power saving and IT environmental issues?<br><br>Thanks,<br>Ashley<br><br>