您的位置:首页 >> Web开发 >> CGI技术 >> 正文
CGI技术 RSS
 

操作系统比对脚本[inststuff.pl]

http://www.rdxx.com 06年08月12日 00:00 我要投稿

关键词: 操作系统 , 脚本 , 操作 , 系统

  #!/usr/bin/perl -w

###########################################################################
# Global definitions
###########################################################################
use Getopt::Long;
$rsync="/usr/local/bin/rsync";
$ssh="/usr/local/bin/ssh";
$rsync_cmd="$rsync -Rapzq --partial -e $ssh";

###########################################################################
# Check for help request. Display help page if --help/-h/-? was passed.
###########################################################################
sub help_page {
my $programname = $0;
$programname =~ s#^\./##;
print "$programname - .\n";
print "\nUsage: $programname <-d directory >\n";
exit 1;
}


sub GetParas
{
my ($argv);

$argv = join(' ',@ARGV);
$argv = join(' ',@ARGV);
&help_page if ( $argv eq "" || $argv =~ m!-h! );
GetOptions("d:s");
if ($opt_d eq "")
{
&help_page;
exit(1);
}
return ($opt_d);

}

sub Env{
if ($> != 0)
{
print ("\nThe command need root permission!\n\n");
exit(1);
}

}



###########################################################################
#Main routine
###########################################################################
sub main
{
my $help = grep(/^--help$/, @ARGV) || grep (/^-h$/, @ARGV) || grep (/^-\?$/, @ARGV) || 0;
help_page() if $help;

#check user uid
&Env;

my $dirs=&GetParas;

#remove file from localhost
if (-e "$dirs/delfilelist")
{
foreach $removefile (`cat $dirs/delfilelist`)
{
chomp($removefile);
if (-e "$removefile")
{
print "---remove---$removefile\n";
system("$rsync_cmd \"$removefile\" $dirs/del/");
system("mv \"$removefile\" \"$dirs/del$removefile\" 2>/dev/null");
}
}
}

#copy newfile to localhost
if (-e "$dirs/addfilelist")
{
foreach $filename (`cat $dirs/addfilelist`)
{
chomp($filename);
chdir("$dirs/filedir");
if(! $filename eq "")
{
print "---add---$filename\n";
system("$rsync_cmd .$filename /");
}
}
}


#update localhost file
if (-e "$dirs/updatefilelist")
{
foreach $updatefile (`cat $dirs/updatefilelist`)
{
chomp($updatefile);
chdir("$dirs/filedir");
if ( -e "$updatefile" )
{
print "---update---$updatefile\n";
system("$rsync_cmd .$updatefile /");
}
}
}
}
&main;

 
 
标签: 操作系统 , 脚本 , 操作 , 系统 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站