脚本 用 scp 拷贝文件

 

#!/usr/bin/expect

set proj_dir /home/jksong/NewsSpark/openid_for_commonid
set tmp_data_dir $proj_dir/data_src/openid_dir
set password yourpassword

spawn scp -r $tmp_data_dir news@10.49.94.67:/data/news/data/commid_stroage_server/original
set timeout 300
for {} {1} {} { 
    expect {
        "*re you sure you want to continue connecting (yes/no)?" {
            send "yes\r" 
        }        
        "*assword:" {
            send "$password\r"
        }        
        "*ermission denied*" {
            break       
        }       
        "*No route to host" {
            break
        }
        "*No such file or directory" {
            break
        }
        timeout {
            break
        }
        eof {
            break
        }
    }
}
interact

exit

 

#!/bin/sh

rsynData()
{
   if [ $# -eq "3" ];then
    src=$1
    dest=$2
    pwd=$3

    expect -c "
        spawn scp -r $src $dest
        expect {
                \"*assword\" {set timeout 300; send \"${pwd}\r\";}
                \"yes/no\" {send \"yes\r\"; exp_continue;}
               }
    expect eof"
   fi
}


rm -rf /data/kb_user_pindao/$1
rsynData [email protected]:/home/jksongNewsHadoop/kb_user_pindao/$1  /data/kb_user_pindao/ password

for p in `ls  "/data/kb_user_pindao/$1"`
do
    /usr/local/php/bin/php /data/inews_server_cms/server/cache_tools/channel_recomm/importInterestChannelToRedis.php /data/kb_user_pindao/$1/$p
done

 

你可能感兴趣的:(脚本 用 scp 拷贝文件)