“Expect基础”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
(创建页面,内容为“=添加pubkey= <pre> vi addkey #!/usr/local/bin/expect #SERVERS="101.00.208.197 120.40.043.52 " set timeout 5 set host [lindex $argv 0] spawn ssh-copy-id -i /…”)
 
第20行: 第20行:
 
用法  
 
用法  
 
./addkey  18.80.216.19 #这是你的IP  
 
./addkey  18.80.216.19 #这是你的IP  
 +
</pre>
 +
=on dovo=
 +
<pre>
 +
#!/usr/bin/expect
 +
#good on new kali  这个在新的kali 上是ok的
 +
set timeout 30
 +
set sshIP "4.88.1.2"
 +
set keypassword "ZdvV"
 +
set rootPassword "5D"
 +
#spawn ssh -o StrictHostKeyChecking=no -i /root/key  evan@$sshIP
 +
expect "Enter passphrase"
 +
send "$keypassword\r"
 +
expect "]$"
 +
send "sudo -i\r"
 +
expect "xxxxx"
 +
send "$rootPassword\r"
 +
expect "]#"
 +
## run command
 +
#send "cat /root/1  && echo 'test was ok .';exit\r"
 +
#send "bash /data/tmp/dbins  && echo 'dbins  was ok.';exit\r"
 +
#expect "52wan"
 +
#send "exit\r"
 +
#expect eof {exit 0}
 +
interact
 +
 +
 +
#!/usr/bin/expect
 +
# on old kali  这个在老的kali
 +
set timeout 30
 +
set sshIP "4.88.1.2"
 +
set keypassword "Zd"
 +
set rootPassword "5D"
 +
spawn ssh -o StrictHostKeyChecking=no -i /home/key  evan@$sshIP
 +
expect "Enter passphrase"
 +
send "$keypassword\r"
 +
expect "52wan"
 +
send "sudo -i\r"
 +
expect "password for 52wan:"
 +
send "$rootPassword\r"
 +
expect "]#"
 +
## run command
 +
#send "cat /root/1  && echo 'test was ok .';exit\r"
 +
#send "bash /data/tmp/dbins  && echo 'dbins  was ok.';exit\r"
 +
#expect "52wan"
 +
#send "exit\r"
 +
#expect eof {exit 0}
 +
interact
 +
 
</pre>
 
</pre>

2019年11月12日 (二) 05:59的版本

添加pubkey


vi addkey

#!/usr/local/bin/expect
#SERVERS="101.00.208.197 120.40.043.52 " 
set timeout 5   
set host [lindex $argv 0]
spawn ssh-copy-id  -i /home/evan/.ssh/id_rsa.pub root@$host
#ssh-copy-id  -i /home/evan/.ssh/id_rsa.pub [email protected]
expect {                  
 "*yes/no" { send "yes\r"; exp_continue}   
 "*password:" { send "P2xMGipLpSG7dA==\r" }       
 }  

expect eof


用法 
	./addkey  18.80.216.19 #这是你的IP 

on dovo

#!/usr/bin/expect
#good on new kali  这个在新的kali 上是ok的
set timeout 30
set sshIP "4.88.1.2"
set keypassword "ZdvV"
set rootPassword "5D"
#spawn ssh -o StrictHostKeyChecking=no -i /root/key  evan@$sshIP
expect "Enter passphrase"
send "$keypassword\r"
expect "]$"
send "sudo -i\r"
expect "xxxxx"
send "$rootPassword\r"
expect "]#"
## run command
#send "cat /root/1  && echo 'test was ok .';exit\r"
#send "bash /data/tmp/dbins   && echo 'dbins  was ok.';exit\r"
#expect "52wan"
#send "exit\r"
#expect eof {exit 0}
interact


#!/usr/bin/expect
# on old kali  这个在老的kali
set timeout 30
set sshIP "4.88.1.2"
set keypassword "Zd"
set rootPassword "5D"
spawn ssh -o StrictHostKeyChecking=no -i /home/key  evan@$sshIP
expect "Enter passphrase"
send "$keypassword\r"
expect "52wan"
send "sudo -i\r"
expect "password for 52wan:"
send "$rootPassword\r"
expect "]#"
## run command
#send "cat /root/1  && echo 'test was ok .';exit\r"
#send "bash /data/tmp/dbins   && echo 'dbins  was ok.';exit\r"
#expect "52wan"
#send "exit\r"
#expect eof {exit 0}
interact