Username: Password:

操作系统比对脚本[inststuff.pl]
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00: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;

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅