微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

scp自动拉取数据

#!/bin/sh
src_dir=要拉取的目录及文件
dest_dir=拉取到本机的目录
host=机器IP
port=38000 (ssh端口:/etc/ssh/sshd_config)
username=root
password=要拉取机器的机器密码
./expect_scp $host $port $username $password $src_dir $dest_dir
echo "pull data end"
#!/usr/bin/expect
set timeout 3600
set host [lindex $argv 0]
set port [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set src_file [lindex $argv 4]
set dest_file [lindex $argv 5]
spawn scp -P $port -r $username@$host:$src_file $dest_file
expect 
{
 "(yes/no)?" 
  {
   send "yes\n"
   expect "*assword:" { send "$password\n"}
  }
  "*assword:" 
  {
   send "$password\n"
  }
}
expect "100%"
expect eof

原文地址:https://www.jb51.cc/centos/376813.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。