#!/usr/bin/perl
#
# synchronizes logfiles to pc15
# 2005-01-10 rwagner@mppmu.mpg.de

system "cd /remote/home/pc4/stesy/Cosy";

sync_dir("rep","rep",3);
sync_dir("log","log",3);
sync_dir("tpoint","txt",3);

sub sync_dir() {
	$directory=$_[0];
	$extension=$_[1];
	$days=$_[2];
	#@files = `ls $directory/`;
	print "find $directory/ -ctime -$days\n";
	@files = `find $directory/ -ctime -$days`;
	foreach (@files) {
		$file=`basename $_`;
		($id,$date,$nr,$ext)=split(/[_\.]/,$file);
		if ($id eq "cosy" || $id eq "tpoint" || $id eq "starg") {
			print "$id_"."$date"."_"."$nr".".$extension -> $date\n";
			system "mkdir -p /remote/disc01/pc15/drivelogs/$date";
			system "rsync $directory/$id"."_"."$date"."_"."$nr".".$extension /remote/disc01/pc15/drivelogs/$date/";
		}
	}
}
