ashsysad
asked on
Need help to complete my perl script
Hello,
I'm trying to develop a perl script (for Linux platform) that will take 'fdisk -l' command output as input and print the Boot device and its disk size.
Below shown are the portion of 'fdisk -l' output and the script which I developed. I need your help to complete this script. I wish to print the 'Size of Boot disk" as well. Please help me in this.
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 6 48163+ 83 Linux
#!/usr/bin/perl
open FILE, "fdisk -l |" or die $!;
foreach(<FILE>)
{
if ( $_ =~ m/(\/dev\/\S+)\s+(\*)\s+/ )
{
print "Boot partition : $1\n";
$boot_disk = "$1";
@value1 = split("1",$boot_disk);
$boot_device = $value1[0];
print "Boot device : $boot_device \n";
}
}
close(FILE);
Expected Result:
Boot partition : /dev/sda1
Boot device : /dev/sda
Size of Boot disk: 21.4 GB <-- My script is missing this.
Some exceptions that we need to take care:
i) The Boot partition needn't be first partition. It can be sda2, sda3 and so on. Hence you may have to change my 'split' statement.
ii) The boot device path needn't be /dev/sdaX. It can be /dev/mapper/boot1 or something else. I'm actually taking '*' as the catching item to determine the disk is a Boot device.
I'm trying to develop a perl script (for Linux platform) that will take 'fdisk -l' command output as input and print the Boot device and its disk size.
Below shown are the portion of 'fdisk -l' output and the script which I developed. I need your help to complete this script. I wish to print the 'Size of Boot disk" as well. Please help me in this.
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 6 48163+ 83 Linux
#!/usr/bin/perl
open FILE, "fdisk -l |" or die $!;
foreach(<FILE>)
{
if ( $_ =~ m/(\/dev\/\S+)\s+(\*)\s+/ )
{
print "Boot partition : $1\n";
$boot_disk = "$1";
@value1 = split("1",$boot_disk);
$boot_device = $value1[0];
print "Boot device : $boot_device \n";
}
}
close(FILE);
Expected Result:
Boot partition : /dev/sda1
Boot device : /dev/sda
Size of Boot disk: 21.4 GB <-- My script is missing this.
Some exceptions that we need to take care:
i) The Boot partition needn't be first partition. It can be sda2, sda3 and so on. Hence you may have to change my 'split' statement.
ii) The boot device path needn't be /dev/sdaX. It can be /dev/mapper/boot1 or something else. I'm actually taking '*' as the catching item to determine the disk is a Boot device.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER