国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Linux > 正文

except自動(dòng)登錄的幾段代碼分享

2019-10-26 18:35:49
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

代碼如下:
#!/usr/bin/expect -f
set timeout 30
set host "192.168.1.198"
spawn ssh $host
expect_before "no)?" {
send "yes/r" }
sleep 1
expect "password:"
send "123456/r"
expect "*#"
send "echo my name is fivetrees > /root/fivetrees.txt/r"
interact

##----------------------------

代碼如下:
[root@fivetrees ~]# cat expect
#!/usr/bin/expect
for {set i 10} {$i <= 12} {incr i} {
set timeout 30
set ssh_user [lindex $argv 0]
spawn ssh -i .ssh/$ssh_user abc$i.com
expect_before "no)?" {
send "yes/r" }
sleep 1
expect "password*"
send "hello/r"
expect "*#"
send "echo hello expect! > /tmp/expect.txt/r"
expect "*#"
send "echo/r"
}
exit

##-------------------------

代碼如下:
#!/usr/bin/expect
if {$argc!=2} {
    send_user "usage: ./expect ssh_user password/n"
    exit
}
foreach i {11 12} {
set timeout 30
set ssh_user [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh -i .ssh/$ssh_user root@xxx.yy.com
expect_before "no)?" {
send "yes/r" }
sleep 1
expect "Enter passphrase for key*"
send "password/r"
expect "*#"
send "echo hello expect! > /tmp/expect.txt/r"
expect "*#"
send "echo/r"
}
exit

##---------------------------

代碼如下:
#!/usr/bin/expect
set timeout 20
if {$argc < 1} {
  puts "Usage: script IP"
  exit 1
}
# 替換你自己的用戶名
set user "username"
#替換你自己的登錄密碼
set password "yourpassword"
foreach IP  $argv {
spawn  ssh $user@$IP
expect /
  "(yes/no)?" {
    send "yes/r"
    expect "password:?" {
      send "$password/r"
    }
  } "password:?" {
    send "$password/r"
}
expect "/$?"
# 替換你要執(zhí)行的命令
send "last/r"
expect "/$?"
sleep 10
send "exit/r"
expect eof
}
使用方法
script_name   ip1  ip2  ip3 ...

##---------------------

代碼如下:
#!/bin/sh
# -*- tcl -*- /
exec tclsh $0 "$@"
package require Expect
set username [lindex $argv 0]
set password [lindex $argv 1]
set argv [lrange $argv 2 end]
set prompt "(%|#|//$) $"
foreach ip $argv {
    spawn ssh -t $username@$ip sh
    lappend ids $spawn_id
}
expect_before -i ids eof {
    set index [lsearch $ids $expect_out(spawn_id)]
    set ids [lreplace $ids $index $index]
    if [llength $ids] exp_continue
}
expect -i ids "(yes/no)//?" {
    send -i $expect_out(spawn_id) yes/r
    exp_continue
} -i ids "Enter passphrase for key" {
    send -i $expect_out(spawn_id) /r
    exp_continue
} -i ids "assword:" {
    send -i $expect_out(spawn_id) $password/r

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 慈溪市| 东安县| 汝州市| 固安县| 获嘉县| 彝良县| 措美县| 玉龙| 甘德县| 车致| 咸宁市| 岑溪市| 政和县| 湘西| 土默特左旗| 彭山县| 洛南县| 全州县| 南京市| 华坪县| 云梦县| 吉林省| 中方县| 二手房| 峨山| 石景山区| 西畴县| 甘孜| 澄城县| 刚察县| 扎兰屯市| 楚雄市| 集贤县| 灵山县| 四会市| 新宁县| 沁阳市| 专栏| 彭山县| 邵东县| 罗田县|