- #!/usr/bin/perl
- #scp.pl filename host password
- #read from a file what to copy by lines and send(through scp) each to host with password
- use warnings;
- use strict;
- use Expect;
- if(@ARGV != 3){
- die "illegal arguments,usage:scp.pl filename host password\n";
- }
- #get the host and the password
- my ($filename,$host,$passwd)=@ARGV;
- #define a file handle to hold the filename
- if(!open FILENAME,"$filename"){
- die "Fail to open $filename:$!\n";
- }
- #begin the expect
- my $exp=Expect->new;
- $exp->log_file("scp.log","w");
- foreach(){
- if($_ ne "\n"){#not blank line
- chomp $_;
- #notice:the host must be the exact location of the web,such as root@192.168.1.12:/usr/local/nginx/html/
- my $scpstr="scp\t".$_."\t".$host.$_."\n";
- print $scpstr;
- $exp=Expect->spawn($scpstr);
- $exp->expect(60,[
- qr/password:/i,
- sub{
- my $self=shift;
- $self->send("$passwd\n");
- exp_continue;
- }
- ],
- [
- 'connecting (yes/no)?',
- sub{
- my $self=shift;
- $self->send("yes\n");
- exp_continue;
- }
- ]);
- }
- }
- $exp->soft_close();
- close FILENAME;
另外新建个文件叫做svnscp.sh吧
用shell写,调用svn update并把得到的参数直接写入到一个svn.log的文件中,再通过调用上面的文件上传
svnscp.sh
- #!/bin/sh
- svn update |grep [UA] |awk -F" " '{print $2}' >svn.log
- scp.pl svn.log hostAndAbsoluteLocation PASSWORD