欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2013年02月09日 17:53:59   作者:  
except自動(dòng)登錄的幾段代碼,大家拿去學(xué)習(xí)吧

復(fù)制代碼 代碼如下:

#!/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

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

復(fù)制代碼 代碼如下:

[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

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

復(fù)制代碼 代碼如下:

#!/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

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

復(fù)制代碼 代碼如下:

#!/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 ...

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

復(fù)制代碼 代碼如下:

#!/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
    exp_continue
} -i ids -re $prompt {
    set spawn_id $expect_out(spawn_id)
    send "echo hello; exit\r"
    exp_continue
} timeout {
    exit 1
}

相關(guān)文章

  • 如何使用 Shell 腳本執(zhí)行 .NET Core 應(yīng)用

    如何使用 Shell 腳本執(zhí)行 .NET Core 應(yīng)用

    這篇文章主要介紹了如何使用 Shell 腳本執(zhí)行 .NET Core 應(yīng)用,幫助大家更好的理解和使用shell 腳本,感興趣的朋友可以了解下
    2020-09-09
  • linux命令行下使用curl命令查看自己機(jī)器的外網(wǎng)ip

    linux命令行下使用curl命令查看自己機(jī)器的外網(wǎng)ip

    Linux命令行下使用curl命令查看自己機(jī)器的外網(wǎng)ip,大家參考使用吧
    2013-12-12
  • Shell腳本獲取進(jìn)程的運(yùn)行時(shí)間

    Shell腳本獲取進(jìn)程的運(yùn)行時(shí)間

    這篇文章主要介紹了Shell腳本獲取進(jìn)程的運(yùn)行時(shí)間,需要的朋友可以參考下
    2014-06-06
  • Linux Shell 如何獲取參數(shù)的方法

    Linux Shell 如何獲取參數(shù)的方法

    這篇文章主要介紹了Linux Shell 如何獲取參數(shù)的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • 一個(gè)簡單的linux命令 tail

    一個(gè)簡單的linux命令 tail

    這篇文章主要介紹了一個(gè)簡單的linux命令tail,tail命令用來從指定點(diǎn)開始將文件寫到標(biāo)準(zhǔn)輸出,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • shell兩個(gè)文件去重的多種姿勢

    shell兩個(gè)文件去重的多種姿勢

    最近在利用shell幫公司優(yōu)化挖掘關(guān)鍵詞的流程,用shell替代了多個(gè)環(huán)節(jié)的操作,極大提高了工作效率。下面這篇文章就給大家分享了利用shell實(shí)現(xiàn)兩個(gè)文件去重的多種姿勢,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-12-12
  • shell腳本監(jiān)控系統(tǒng)負(fù)載、CPU和內(nèi)存使用情況

    shell腳本監(jiān)控系統(tǒng)負(fù)載、CPU和內(nèi)存使用情況

    這篇文章主要介紹了shell腳本監(jiān)控系統(tǒng)負(fù)載、CPU和內(nèi)存使用情況,本文分別給出監(jiān)控服務(wù)器系統(tǒng)負(fù)載情況、監(jiān)控系統(tǒng)cpu使用情況、、監(jiān)控系統(tǒng)內(nèi)存情況、監(jiān)控系統(tǒng)交換分區(qū)swap使用情況的腳本,需要的朋友可以參考下
    2014-12-12
  • linux下的tar命令詳細(xì)解釋

    linux下的tar命令詳細(xì)解釋

    在Linux中,壓縮與解壓用得最多的tar.tar命令確實(shí)很厲害。下面通過本文給大家分享linux下的tar命令詳細(xì)解釋,感興趣的朋友一起看看吧
    2017-08-08
  • linux 獲取某個(gè)日期對應(yīng)的月末日期方法

    linux 獲取某個(gè)日期對應(yīng)的月末日期方法

    今天小編就為大家分享一篇linux 獲取某個(gè)日期對應(yīng)的月末日期方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Linux 命令之rsync命令詳解

    Linux 命令之rsync命令詳解

    rsync命令是一個(gè)遠(yuǎn)程數(shù)據(jù)同步工具,可通過LAN/WAN快速同步多臺(tái)主機(jī)間的文件。下面通過本文給大家分享Linux 命令之rsync命令詳解,需要的朋友參考下吧
    2017-08-08

最新評論