码迷,mamicode.com
首页 > 其他好文 > 详细

expect

时间:2017-10-19 12:51:54      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:expect

#!/usr/bin/expect

set host 192.168.1.124

set user root

set password "root"

spawn ssh $user@$host

expect "yes/no" { send "yes\r" }

expect "password:" { send "$password\r" }

expect "\[$user\@" { send "pwd > /tmp/$user.txt ; exit\r" }

interact 


------------------------------------------------------------->脚本传参$1 = set host [lindex $argv 0]

#!/usr/bin/expect

set host [lindex $argv 0]

set user root

set password "root"

spawn ssh $user@$host

expect "yes/no" { send "yes\r" }

expect "password:" { send "$password\r" }

expect "\[$user\@" { send "echo ‘my name is you!‘ > /tmp/$user.txt ; exit\r" }

interact


------------------------------------------------------------------>

#!/bin/bash

known_file=/root/.ssh/known_hosts

rm -rf ${known_file:-/tmp/*}

expect <<EOF

set timeout 5

spawn ssh root@192.168.4.8

expect "password" {send "123456\r"}

expect "#" {send "echo ‘my name is you‘ >/tmp/root7.txt\r"}

expect "#" {send "exit\r"}

EOF


------------------------------------------------------->给254台安装httpd服务

#!/bin/bash

known_file=/root/.ssh/known_hosts

rm -rf ${known_file:-/tmp/*}

for i in $(seq 254)

do

expect <<EOF

spawn ssh root@192.168.4.$i

expect "yes/no" {send "yes\r"}

expect "password" {send "123456\r"}

expect "#" {send "echo ‘yum -y install httpd\r"}

expect "#" {send "exit\r"}

EOF

done


------------------------------------------------------>给254发密钥 ssh-copy-id

#!/bin/bash

for i in $(seq 254)

do

expect <<EOF

spawn ssh-copy-id root@192.168.4.$i

expect "yes/no" {send "yes\r"}

expect "password" {send "123456\r"}

expect "#" {send "exit\r"}

EOF

done




本文出自 “12177655” 博客,谢绝转载!

expect

标签:expect

原文地址:http://12187655.blog.51cto.com/12177655/1974022

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!