发新话题
打印

[求助] 怎样查询域中一段时间内没有使用过的视图?( 此文章被查看:144次,被回复:4篇!! )

怎样查询域中一段时间内没有使用过的视图?

我知道用下述命令可以显示域中所有视图,以及视图最后一次使用时间:lsview -l -age -region
但是如果想查询几个月内没有使用过的视图有哪些,应该怎样修改上述命令呢?



© 本文为 yingzi3608SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

建议用脚本实现复杂些的功能。



© 本文为 somisSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

找到了一个脚本,但是那位能帮忙解释一下,看不太懂??

#!/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";

}

################################



© 本文为 yingzi3608SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

引用:
原帖由 yingzi3608 于 2008-5-9 20:53 发表
我知道用下述命令可以显示域中所有视图,以及视图最后一次使用时间:lsview -l -age -region
但是如果想查询几个月内没有使用过的视图有哪些,应该怎样修改上述命令呢?
如果您觉得脚本麻烦,有个比较简单的方法:
统计所有view storage目录下view_db.state文件的最后一次访问时间,和当前时间对比,超过几个月以上的,都是应该删除的.

[ 本帖最后由 cn_chenfeng 于 2008-5-14 21:09 编辑 ]

© 本文为 cn_chenfeng 所有,未经同意,请勿转载
©如该文侵犯了您的版权,请联系管理员

TOP

那样做和我前面提到的命令(lsview -l -age -region)做法是一样的,视图如果特别多的话实行起来难度太大

© 本文为 yingzi3608 所有,未经同意,请勿转载
©如该文侵犯了您的版权,请联系管理员

TOP

发新话题