- expect
except是一种自动交互语言,能实现在shell脚本中为scp和ssh等自动输入密码自动登录
#!/usr/bin/expect
#远程登陆
set timeout 30
set host "root@IP"
spawn scp $host
expect {
"password:"{send "pwd\r";}
"yes/no" {send "yes\r";}
}
interact
#远程登陆并复制文件到本地
set host "root@IP"
set remote_file "file_name"
set local_dir "dir_name"
spawn scp $host:$file $local_dir
expect {
"password:"{send "pwd\r";}
"yes/no" {send "yes\r";}
}
interact
复制目录:
(1)将本地目录拷贝到远程
scp -r 目录名用户名@计算机IP或者计算机名称:远程路径
(2)从远程将目录拷回本地
scp -r 用户名@计算机IP或者计算机名称:目录名本地路径