#!/usr/bin/expect -f#The author storoysky#IDC login setset 9009user "xman"set 9009pass "A9QJxMuE;O"set 9009ip "192.168.1.9"set 9009prompt "~]#"#跳板机 login setset tl_bpw "8xgcv0D8cp"set tl_bprompt ":~$"#合作商服务器 setset hostip [lrange $argv 0 0]set hostpw "2xP;unlUPM"spawn ssh -p 9009 $9009user@$9009ipset timeout 5expect "password:"send "$9009pass\r"expect "$9009prompt"send "ssh m_xman@172.16.1.9 -p36000 \r"expect "password:"send "$tl_bpw\r"expect ":~$"send "ssh -p 36000 m_xman@$hostip\r"expect "password:"send "$hostpw\r"expect "Ten64:/>"send "sudo su - user_00\r"interact #将交互权限还给用户
scp命令用法:
scp 用户名@密码:文件目录名字 用户名@密码:目录名字
例子:
A . scp /root/btest.txt
将远程机子192.168.100.130上的root下的atest.txt拷贝倒本机并改名为btest.txt
B. scp /root/test1
将本机的root下的test1 拷贝到远程的192.168.100.130的root下并改名为test2
expect例子
#!/usr/bin/expect
spawn ssh 192.168.100.130
expect "password:"
send "123456\r"
send "ls -l > 123.txt\r"
#send "exit"
interact
实现了自动登陆到 192.168.100.130 并执行命令 ls -l >123.txt