远程登录的简单expect脚本
时间:2014-09-10 18:25 来源:linux.it.net.cn 作者:it
用于远程登录的简单expect脚本。
复制代码代码如下:
#!/usr/bin/expect -f
#The author storoysky
#IDC login set
set 9009user "xman"
set 9009pass "A9QJxMuE;O"
set 9009ip "192.168.1.9"
set 9009prompt "~]#"
#跳板机 login set
set tl_bpw "8xgcv0D8cp"
set tl_bprompt ":~$"
#合作商服务器 set
set hostip [lrange $argv 0 0]
set hostpw "2xP;unlUPM"
spawn ssh -p 9009 $9009user@$9009ip
set timeout 5
expect "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@192.168.100.130:/root/atest.txt /root/btest.txt
将远程机子192.168.100.130上的root下的atest.txt拷贝倒本机并改名为btest.txt
B. scp /root/test1 root@192.168.100.130:/root/test2
将本机的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。
(责任编辑:IT)
用于远程登录的简单expect脚本。
复制代码代码如下:
#!/usr/bin/expect -f
#跳板机 login set
#合作商服务器 set
spawn ssh -p 9009 $9009user@$9009ip
expect "$9009prompt"
expect "password:"
expect ":~$"
expect "password:"
expect "Ten64:/>"
scp命令用法:
复制代码代码如下:
#!/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。 (责任编辑:IT) |