Perl script for Data-gen

This is a continuation of the previous script where you can use the script to create the partition on the disks which doesn’t have a FS created. The following script can help to generate the data sets on those disk, and it can do the write dynamically based on the disks to be operated.



use Time::Local;
use Parallel::ForkManager;
package main;  

  if ( @ARGV != 3 ) {
 $! = 1;
 die "USAGE: <testcasename.pl> profilepath datagen_size no_of_files\n";
}
$profile = shift(@ARGV);
print $profile;
$ostype="$^O\n";
print $ostype;
$size=shift(@ARGV);
print "\n The size to create data is  $size GB";
chop $ostype;
$count=$size*1024;
$no_of_files=shift(@ARGV);
print $no_of_files;
print "Total Size is $count MB to be created";

print "\n Sleeping the script for couple of minutes to ensure the VM is up and configured";
#sleep 120;
open (TR, "<$profile") or die "Test list is not found please create one or run the configuration";
@listuuid=<TR>;
close (TR);
$listofvm=@listuuid;

$max_forks = new Parallel::ForkManager(2);
foreach $testuuid (@listuuid){
		$max_forks->start and next;
#	  
         chomp $testuuid;
for ($i=1;$i<=3;$i++)
{


$file = "log_partition.txt";

   if (! open (LOG, ">>$file"))
  {
    print "logprint: could not write to log file: $file!\n";
    
   }
  print LOG " Starting disk paritioning";
  close LOG;

print "\n There are total of $listofvm VM it will start performing the task";


         
for ($k=1;$k<=$no_of_files;$k++){

	   
		$datagen= " dd if=\/dev\/urandom of=\/disk-$i\/ran-file$k.txt count=$count bs=1M  ";
		print $datagen;
		&plink ($testuuid,$datagen);
        # system(" dd if=/dev/urandom of=/disk-5/random-file-40G.txt count=10000 bs=4M & ");

}		 
		

		
}		
	$max_forks->finish;
}	$max_forks->wait_all_children;
		
		
		
sub plink ($)
{
		   my $server=shift;
		   my $run_command=shift;
			print $run_command;
			my $user = "root";
			my $password = "psswd";
			my $plink="plink";
			print $run_command;
			print "\n Verify the platform Win or Linux";
			if ($ostype eq "MSWin32")
			{
print "\n Running on Windows";
			$ssh_command = qx(echo n | $plink -ssh -v -pw $password $user\@$server "$run_command");
			print $ssh_command;
		    return $ssh_command;
			}if ($ostype eq "linux")
			{
			       print "\n Running in linux platform";
			       $ssh_command1=" sshpass -p $password ssh  -o StrictHostKeychecking=no -t root\@$server $run_command ";
			       print "\n $ssh_command"; 
		               $out1= qx($ssh_command1);
			       print $out1;
			       return $out1;
				
			}
		} #end of plinkexec

sub printlog ($)
{
	my $string = shift(@_);
   	my $file = "log_partition.txt";
   	#print $file;
    print $string;
    $date = scalar(localtime);
	$date =~ s/\s+/_/g;
	$date =~ s/::/_/;
	$date=~s/:/_/g;
		
   if (! open (LOG, ">>$file"))
  {
    print "logprint: could not write to log file: $file!\n";
    print "$string";
    return 1;
  }
  print LOG " $string";
  close LOG;
  print "$string";

  return 0;
}