1. #!/usr/bin/perl 
  2. #scp.pl filename host password 
  3. #read from a file what to copy by lines and send(through scp) each to host with password  
  4. use warnings; 
  5. use strict; 
  6. use Expect; 
  7.  
  8. if(@ARGV != 3){ 
  9. die "illegal arguments,usage:scp.pl filename host password\n"
  10.  
  11. #get the host and the password 
  12. my ($filename,$host,$passwd)=@ARGV; 
  13.  
  14. #define a file handle to hold the filename 
  15. if(!open FILENAME,"$filename"){ 
  16. die "Fail to open $filename:$!\n"
  17.  
  18. #begin the expect 
  19. my $exp=Expect->new; 
  20.  
  21. $exp->log_file("scp.log","w"); 
  22.  
  23. foreach(){ 
  24. if($_ ne "\n"){#not blank line 
  25. chomp $_; 
  26. #notice:the host must be the exact location of the web,such as root@192.168.1.12:/usr/local/nginx/html/ 
  27. my $scpstr="scp\t".$_."\t".$host.$_."\n"
  28. print $scpstr; 
  29. $exp=Expect->spawn($scpstr); 
  30. $exp->expect(60,[ 
  31. qr/password:/i, 
  32. sub{ 
  33. my $self=shift; 
  34. $self->send("$passwd\n"); 
  35. exp_continue; 
  36. ], 
  37. 'connecting (yes/no)?'
  38. sub{ 
  39. my $self=shift; 
  40. $self->send("yes\n"); 
  41. exp_continue; 
  42. ]); 
  43. $exp->soft_close(); 
  44. close FILENAME; 

 另外新建个文件叫做svnscp.sh吧

用shell写,调用svn update并把得到的参数直接写入到一个svn.log的文件中,再通过调用上面的文件上传

svnscp.sh

 

 
  
  1. #!/bin/sh 
  2. svn update |grep [UA] |awk -F"    " '{print $2}' >svn.log 
  3. scp.pl svn.log hostAndAbsoluteLocation PASSWORD