#!/usr/bin/expect
set timeout 10
spawn scp /home/chent/admin.tgz root@IP:/home/serverop/
expect "password:"
send "xxxxxxx\r"
interact
脚本如下:\x0d\x0a\x0d\x0a#!/usr/bin/expect -f\x0d\x0a\x0d\x0aset password 密码\x0d\x0a\x0d\x0aspawn scp 用户名@目标机器ip:拷贝文件的路径 存放本地文件的路径 \x0d\x0aset timeout 300 \x0d\x0aexpect "用户名@目标机器ip's password:" #注意:这里的“用户名@目标机器ip” 跟上面的一致\x0d\x0aset timeout 300 \x0d\x0asend "$password\r"\x0d\x0aset timeout 300 \x0d\x0asend "exit\r"\x0d\x0a\x0d\x0aexpect eof\x0d\x0a\x0d\x0a附:scp参数\x0d\x0a-r:拷贝目录\x0d\x0a-c:允许压缩\x0d\x0a\x0d\x0a一个完整的例子\x0d\x0a\x0d\x0a#!/usr/bin/expect -f\x0d\x0aset password 123456\x0d\x0a#download\x0d\x0aspawn scp root@192.168.1.218:/root/a.wmv /home/yangyz/\x0d\x0aset timeout 300 \x0d\x0aexpect "root@192.168.1.218's password:"\x0d\x0aset timeout 300 \x0d\x0asend "$password\r"\x0d\x0aset timeout 300 \x0d\x0asend "exit\r"\x0d\x0aexpect eof \x0d\x0a\x0d\x0a#upload\x0d\x0aspawn scp /home/yangyz/abc.sql root@192.168.1.218:/root/test.sql \x0d\x0aset timeout 300 \x0d\x0aexpect "root@192.168.1.218's password:"\x0d\x0aset timeout 300 \x0d\x0asend "$password\r"\x0d\x0aset timeout 300 \x0d\x0asend "exit\r"\x0d\x0aexpect eof欢迎分享,转载请注明来源:内存溢出
评论列表(0条)