| 1 | package Ixchel::functions::serial; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use File::Slurp; | ||
| 7 | use Exporter 'import'; | ||
| 8 | our @EXPORT = qw(serial_num); | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Ixchel::functions::serial - Returns either system serial or baseboard serial found via dmidecode. | ||
| 13 | |||
| 14 | =head1 VERSION | ||
| 15 | |||
| 16 | Version 0.0.1 | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | our $VERSION = '0.0.1'; | ||
| 21 | |||
| 22 | =head1 SYNOPSIS | ||
| 23 | |||
| 24 | use Ixchel::functions::serial; | ||
| 25 | |||
| 26 | print 'Serial: '.serial_num."\n"; | ||
| 27 | |||
| 28 | =head1 Functions | ||
| 29 | |||
| 30 | =head2 serial_num | ||
| 31 | |||
| 32 | Fetches either system-product-name or baseboard-serial-number via dmidecode. | ||
| 33 | |||
| 34 | First system-serial-number is tried and if that matches /To be/, then | ||
| 35 | baseboard-serial-number is used. | ||
| 36 | |||
| 37 | If not ran as root, this will return blank. | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub serial_num { | ||
| 42 | my $output = `dmidecode --string=system-serial-number 2> /dev/null`; | ||
| 43 | if ( $output =~ /To be/ ) { | ||
| 44 | $output = `dmidecode --string=baseboard-serial-number 2> /dev/null`; | ||
| 45 | } | ||
| 46 | |||
| 47 | chomp($output); | ||
| 48 | |||
| 49 | return $output; | ||
| 50 | } | ||
| 51 | |||
| 52 | 1; |