找到了一个脚本,但是那位能帮忙解释一下,看不太懂??
#!/usr/bin/env perl -w
#filename autormview.pl
#among, V1.0 20061220
#copyright,
www.scmlife.com
#MSN :
lifeng29@msn.com
use Net:ing;
use Sys::Hostname;
$thishost=hostname;
$ct="cleartool";
$ccreg="clearcs2"; ##clearcase registry server hostname
$day=365; ##day
####################################
$OS="$ENV{'OS'}";
if ($OS=~ m/windows/i)
{
$nul="NUL";
$rmcommand="rmdir /S/Q ";
$dirline="\\";
}
else
{
$nul="/dev/null";
$rmcommand="rm -fr ";
$dirline="/";
}
####################################
##################rgy_check first #####################
@regerr=`rgy_check -views 2>&1 1>$nul`;
if ($#regerr eq -1)
{
print "There is no view registry error in this region \n";
}
else
{
@regerr=&viewinfo(@regerr);
foreach (@regerr)
{
if ($_=~ m/This view object is stranded/)
{
$uuid=$1 if ($_=~ m/-view_uuid = "(\S+)"/);
&rmref($uuid) if defined($uuid);
&unreg($uuid) if defined($uuid);
}
if ($_=~ m/This view tag has no view object with the same UUID/)
{
$tag=$1 if ($_=~ m/-tag = "(\S+)"/);
$uuid=$1 if ($_=~ m/-view_uuid = "(\S+)"/);
&rmref($uuid) if defined($uuid);
&rmtag($tag) if defined($tag);
}
else
{
print "lease check this $_\n";
}
}
print "rgy_check view complete!"
}
############################################
######ls view###########
@allview=`$ct lsview -long 2>$nul`;
if ($#allview eq -1)
{
print "There is no view in this region\n";
exit 0;
}
else
{
@allview=&viewinfo(@allview);
foreach (@allview)
{
$viewattr=$1 if ($_=~ m/View attributes: (\S+)/);
$serverhost=$1 if ($_=~ m/Server host: (\S+)/);
CHECKVIEW:
{
if (&pinghost($serverhost))
{
RMVIEW:
{
if ((defined($viewattr)) && ($viewattr =~ m/.*webview/))
{
last CHECKVIEW if ($serverhost ne $thishost);
$gpath=$1 if ($_=~ m/View server access path: (\S+)/);
$uuid=$1 if ($_=~ m/View uuid: (\S+)/);
$viewtag=$1 if ($_=~ m/Tag: (\S+)/);
$accessfile=$gpath.$dirline.".access_info";
if (-f $accessfile)
{
&rmview($gpath,$uuid,$viewtag) if ((-M $accessfile) > $day);
last CHECKVIEW;
}
else
{
&rmview($gpath,$uuid,$viewtag);
}
}
else
{
$gpath=$1 if ($_=~ m/Global path: (\S+)/);
$uuid=$1 if ($_=~ m/View uuid: (\S+)/);
$viewtag=$1 if ($_=~ m/Tag: (\S+)/);
$accessfile=$gpath.$dirline.".access_info";
if (-f $accessfile)
{
&rmview($gpath,$uuid,$viewtag) if ((-M $accessfile) > $day);
last CHECKVIEW;
}
else
{
&rmview($gpath,$uuid,$viewtag);
}
}
}
}
else
{
@hostlist=`$ct lsclients -host $ccreg -type all -s 2>$nul`;
foreach $clienthost (@hostlist)
{
chomp($clienthost);
CHECKHOST:
{
last CHECKVIEW if ($serverhost =~ m/\d+\.\d+\.\d+\.\d+/);
if ($serverhost =~ m/^($clienthost)/i)
{
print "I find $serverhost !\n";
last CHECKVIEW;
}
last CHECKHOST;
}
}
{
print "I not find $serverhost \n";
goto RMVIEW;
}
}
}
undef($viewattr);
undef($serverhost);
}
}
#############sub################
sub viewinfo()
{
@view1=@_;
my $a=0;
my @view2=();
foreach $count (0..$#view1)
{
if ($view1[$count] eq "\n")
{
$count=$count-1;
$viewstring=join '',@view1[$a..$count];
push(@view2,$viewstring);
$a=$count+2;
}
}
return @view2;
}
################################
sub rmref
{
system("$ct rmview -force -all -uuid $_[0]");
}
sub rmtag
{
system("$ct rmtag -view -all $_[0]");
}
sub unreg
{
system("$ct unreg -view -uuid $_[0]");
}
sub rmstg
{
system("$rmcommand $_[0]");
}
sub endview
{
system("ct endview -server $_[0]");
}
################################
sub pinghost()
{
$host=shift(@_);
$p = Net:ing->new();
return 1 if $p->ping($host);
$p->close();
return 0;
}
#################################
sub rmview()
{
$a=shift(@_);
$b=shift(@_);
$c=shift(@_);
&endview($c);
&rmref($b);
&unreg($b);
&rmtag($c);
&rmstg($a);
# print "$c\n";
}
################################