scp 자동 업로드

5426 단어 SVNscp

  
  
  
  
  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
    "
    ; 
  10. } 
  11.  
  12. #get the host and the password 
  13. my ($filename,$host,$passwd)=@ARGV; 
  14.  
  15. #define a file handle to hold the filename 
  16. if(!open FILENAME,"$filename"){ 
  17. die "Fail to open $filename:$!
    "
    ; 
  18. } 
  19.  
  20. #begin the expect 
  21. my $exp=Expect->new; 
  22.  
  23. $exp->log_file("scp.log","w"); 
  24.  
  25. foreach(){ 
  26. if($_ ne "
    "
    ){#not blank line 
  27. chomp $_; 
  28. #notice:the host must be the exact location of the web,such as [email protected]:/usr/local/nginx/html/ 
  29. my $scpstr="scp\t".$_."\t".$host.$_."
    "
    ; 
  30. print $scpstr; 
  31. $exp=Expect->spawn($scpstr); 
  32. $exp->expect(60,[ 
  33. qr/password:/i, 
  34. sub{ 
  35. my $self=shift; 
  36. $self->send("$passwd
    "
    ); 
  37. exp_continue; 
  38. } 
  39. ], 
  40. [ 
  41. 'connecting (yes/no)?', 
  42. sub{ 
  43. my $self=shift; 
  44. $self->send("yes
    "
    ); 
  45. exp_continue; 
  46. } 
  47. ]); 
  48. } 
  49. } 
  50. $exp->soft_close(); 
  51. close FILENAME; 

또 새 파일은svnscp라고 합니다.sh
셸로 쓰고svn 업데이트를 호출하여 얻은 매개 변수를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 

좋은 웹페이지 즐겨찾기