Advertisement
digimer

Untitled

Dec 28th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.20 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # This is a wrapper for dmidecode that will return the configured UUID
  4. # when 'dmidecode -s system-uuid' is called. Otherwise, it will call dmidecode
  5. # and return as appropriate.
  6. #
  7.  
  8. use strict;
  9. use warnings;
  10. use IO::Handle;
  11.  
  12. # Desired System UUID
  13. my $uuid;
  14. my $exit=0;
  15. my $sub=0;
  16.  
  17. # Read command line.
  18. my $cla="";
  19. foreach my $arg (@ARGV) { $cla.=$arg." "; }
  20. $cla=~s/\s+$//;
  21.  
  22. if ($cla eq "-q -t 0,1,4,17")
  23. {
  24.     $sub=1;
  25. }
  26.  
  27. # Read the UUID from /etc/libvirt/libvirtd.conf.
  28. my $sc="</etc/libvirt/libvirtd.conf";
  29. my $fh=IO::Handle->new();
  30. open ($fh, $sc) or die "$!";
  31. while (<$fh>)
  32. {
  33.     chomp;
  34.     my $line=$_;
  35.     next if $line =~ /^#/;
  36.     if ($line =~ /host_uuid/)
  37.     {
  38.         ($uuid)=($line =~ /"(.*?)"/);
  39.     }
  40. }
  41. $fh->close();
  42.  
  43. # Call the real dmidecode
  44. $sc="/usr/sbin/dmidecode.orig $cla 2>&1 |";
  45. $fh=IO::Handle->new();
  46. open ($fh, $sc) or die $!;
  47. while (<$fh>)
  48. {
  49.     chomp;
  50.     my $line=$_;
  51.     # If I found a UUID, this line is the UUID and I am doing a
  52.     # substitution, well, do it already.
  53.     if (($uuid) && ($line=~/(\s+)UUID: /) && ($sub))
  54.     {
  55.         my $space=$1;
  56.         print "${space}UUID: $uuid\n";
  57.     }
  58.     else
  59.     {
  60.         print $line, "\n";
  61.     }
  62. }
  63. $fh->close();
  64. $exit=$?;
  65.  
  66. exit($exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement