Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

  1. #!perl
  2. #
  3. # gethname.pl
  4. #
  5. # write %temp%\_hname.cmd that when called, will set env. var HOSTNAME with
  6. # either the node name or the cluster mgmt name
  7. #
  8. # get the node's name; stuff it in $hname as the default in case any of the other
  9. # stuff fails.
  10. $our_hostname = $ENV{COMPUTERNAME};
  11. $hname = $our_hostname;
  12. # get the list of cluster resources and their hosting node
  13. $resources_cmd = "cluster res \"cluster name\" | ";
  14. if (open( RESLIST, $resources_cmd )) {
  15. while ($line = <RESLIST>) {
  16. chomp( $line );
  17. # print "line:", $line, "\n";
  18. if ( $line =~ /\s*System error\s*/ ) {
  19. # something bad happened; use COMPUTERNAME
  20. print STDERR "cluster.exe returned an error: ", $line, "\n";
  21. last;
  22. }
  23. # looking for:
  24. # Cluster Name <Group Name> <node name> Online
  25. #
  26. # group name can have any number of white spaces in between
  27. # the words so we'll key off of "Cluster Name" which can't
  28. # change and "Online". If the name is offline, then we'll use
  29. # COMPUTERNAME
  30. if ( $line =~ /^cluster name\s+.+\s+(\S+)\s+Online\s*$/ ) {
  31. $hosting_node = $1;
  32. print "Cluster name online at ", $hosting_node, "\n";
  33. # found the name and it is online. now dump its properties to
  34. # get the actual name
  35. if ( open( RESPROPS, "cluster res \"cluster name\" /priv | " )) {
  36. while ( $propline = <RESPROPS> ) {
  37. chomp( $propline );
  38. if ( $propline =~ /^S\s+cluster name\s+Name\s+(\S+)\s*$/ ) {
  39. $hname = $1;
  40. print "cluster name is: ", $hname, "\n";
  41. last;
  42. }
  43. }
  44. close( RESPROPS );
  45. }
  46. last;
  47. }
  48. }
  49. # see if we found something
  50. if ( !$hosting_node ) {
  51. print "Cluster name doesn't appear to be online\n";
  52. }
  53. } else {
  54. print STDERR "Cluster.exe command failed\n";
  55. }
  56. close( RESLIST );
  57. # write hostname to cmd file
  58. if ( open( CMDFILE, ">$ENV{TEMP}\\_hname.cmd" )) {
  59. print CMDFILE "set HOSTNAME=", $hname, "\n";
  60. close( CMDFILE );
  61. } else {
  62. print "Can't open:", $ENV{TEMP}, "\\_hname.cmd\n";
  63. }