#!/usr/bin/perl ## $Id: splitn,v 1.2 2011/04/08 13:35:11 pdc Exp $ ## (c) Pavel Polyakov 2011 my $src; my $n=0; my $dirs=0; my $err=0; for my $A (@ARGV) { if($n==0) { # file name $src=$A; } elsif($n>0) { # dir N if($A=~m%^(.+?)(:([0-9]+)?([km])?)?$%i) { my($dir,$size,$block)=($1,$3,$4); if($block=~/^$|m/i) { } elsif($block=~/xxxx/i) { } else { print STDERR "bad block: $block\n" }; $size+=0; push @DIRS, $dir; push @SIZE, $size; # kb $dirs++; } else { $err++; print STDERR "Unknown arg: $A\n"; } } $n++; } if($src ne '') { $sizeb=-s $src; #$sizeb=$size; $sizek=int($sizeb/1024+0.9999); $sizem=int($sizeb/1024/1024+0.9999); print STDERR "src: $src ($sizeb = ${sizek} K = ${sizem} M)\n"; } $rest=$sizem; $offs=0; $n1=0; for $dir (@DIRS) { my $size1= $SIZE[$n1]; my $last=0; if($size1>0) { $rest-=$size1; } else {$size1=$rest;$last=1}; print STDERR "dest: $dir size $size1\n"; $res=system("df -k $dir |grep -v Filesystem"); print STDERR "err $res $!\n" if $res!=0; $count= !$last ? "count=$size1 " : ''; $dd.="dd conv=notrunc,sync bs=1024k if=$src oseek=0 iseek=$offs $count of=$dir/$src.$offs\n"; $offs+=$size1; $n1++; } if(!defined($src)) { print STDERR "Usage: \n splitn /dir1:size1 [/dir2:size2] [...]\n"; exit 2; } print $dd; __END__