よく使うスクリプト集

Last-modified: 2007-02-22 (木) 16:25:26

#analyzer


HDDのフォーマット

#fdisk /dev/hda
>d // パーティションテーブルからいらないものを削除
>n // 新たなパーティション作成
>w // パーティションテーブルの反映
#mkfs -t ext3 /dev/hda1

DVD2ISO

dvdbackup -M -i/dev/dvd -o/tmp/dvdwork
mkisofs -udf -dvd-video -o~/<TITLE>.iso /tmp/dvdwork/<TITLE>

再帰的にディレクトリ配下のファイルを対象に任意の処理を行う (recursive.pl)

package recursive;
sub trimer
{
	$var = shift;
	$var =~ s/^\s*(.+?)\s*[\/,\\]*\s*$/$1/;
	return $var;
}
sub go_func
{
	my $target = shift;
	if (!defined ($func)) {
		return 0;
	}
	&$func ($target);
}
sub recursive_dir
{
	my $fullpath = trimer (shift);
	#print "enter dir ... \"".$fullpath."\"\n";
	my $command = "ls \"$fullpath\"";
	my @items = `$command`;
	foreach my $item (@items)
	{
		my $file = trimer ($item);
		my $target = "$fullpath/$file";
		if (-d $target)
		{
			recursive_dir ($target);
		}
		else
		{
			go_func ($target);
		}
	}
}
sub recursive
{
	$func = shift;
	my $top = trimer (shift);
	if (!defined ($top)) {
		$top = '.';
	}
	if (-d $top)
	{
		recursive_dir ($top);
	}
	else
	{
	 	go_func ($top);
	}
}
1;

使い方

ホームディレクトリ以下のファイルを列挙します

require ("recursive.pl");
sub func
{
	print shift;
}
my $dir = "/home";
recursive::recursive (\&func, $dir);