I try to get a specific output from a simple perl command en write it to a variable to use in a later stadium in my script.
I have to following code:
#!/usr/bin/perl
use strict;
use warnings;
my $serial = system("hdparm -I /dev/sda | grep 'Serial Number:'");
print $serial;
This generates the following output:
0root@spool-B-01:~# ./test.pl
Serial Number: 9VS3D79X
But i need the output to be as followed:
0root@spool-B-01:~# ./test.pl
9VS3D79X
I have tried some things with awk and sed. But that won't give the output the way i need it.
For example:
#!/usr/bin/perl
use strict;
use warnings;
use Sys::Hostname;
my $serial = system("hdparm -I /dev/sda | grep 'Serial Number:' | sed -e 's/Serial Number://g'");
print $serial;
Show the output like:
0root@spool-B-01:~# ./test.pl
9VS3D79X
It is almost correct but you still got the tabs before the serial code.
I hope that somebody can help me figure this stuff out and do it the correct way.