Cover V09, I04
Article
Listing 1
Listing 2
Listing 3

apr2000.tar


Listing 1: Delete all partitions

use Expect;

my $Fdisk = Expect->spawn("/sbin/fdisk /dev/hda");
my $match=$Fdisk->expect(30,"Command (m for help):");
print $Fdisk "p\n";
$match=$Fdisk->expect(30,"Device Boot    Start");

my $Temp = $Fdisk->exp_after();
my @Temp = split(/\n/, $Temp);
my @Partitions = grep($_ =~ /^\/dev\//, @Temp);
  
foreach my $Line (reverse @Partitions)
  {
  my ($Part,$Junk) = split(/[\t ]/, $Line,2);
  my $No = $Part;
  $No =~ s/^\/dev\/$Drive//;

  print "Deleting no $Drive $No\n";     

  print $Fdisk "d\n";    
  $match=$Fdisk->expect(30,"Partition number");

  print $Fdisk "$No\n";
  $match=$Fdisk->expect(30,"Command (m for help):");
  }
print $Fdisk "w\n"; $Fdisk->expect(30,"Command (m for help):");