循环具有特定条件的函数

时间:2015-09-28 17:06:46

标签: linux unix expect

我有一个功能:

Ext.create('Ext.form.Panel', {
    renderTo: Ext.getBody(),
    width: 175,
    height: 150,
    bodyPadding: 10,
    title: 'Final Score',
    items: [{
        xtype: 'displayfield',
        fieldLabel: 'Home',
        name: 'home_score',
        value: '10'
    }, {
        xtype: 'displayfield',
        fieldLabel: 'Visitor',
        name: 'visitor_score',
        value: '11'
    }],
    buttons: [{
        text: 'Update'
    }]
});

set timeout 20 set f [open "password.txt"] set password [read $f] close $f spawn ssh user@example.net -p 724 expect "user@example.net's password:" send $password interact 我只有一个字

在终端中使用expect运行此脚本后,如果存在正确的单词,则可以访问服务器。

我有两个问题:

求助--------- 1)我想以这样的方式循环执行这个脚本,以防我在password.txt中有2,5,100个单词,脚本会尝试全部他们是密码,不仅是现在的第一个。

2)如果我将设法使用来自的所有单词循环执行该函数 password.txt,我需要使用if语句来解决这个问题(在3次尝试写密码服务器之后断开连接,所以你需要在每次尝试3次后再次连接。)

更新:服务器在最后一次尝试(第3次)之后的前2次尝试(例如password.txt)之后回答,它说Permission denied, please try again.并且它将我发送到我的正常命令线状态。

我正在尝试做类似

的事情
Permission denied (publickey,password).

但不知道如何在expect语法中实现此逻辑。

直到现在我设法写了这个

while read line
 do
  echo "Trying: $line"
  echo ssh user@example.net -p 724 --password "$line" ## NOT REAL CODE
 done < password.txt

它解决了我的第一个问题,但问题是我需要按manaul&#34;输入&#34;服务器请求密码后。在我点击&#34;进入&#34;该脚本尝试列表中的第一个单词,如果它再次出错,我需要按&#34;输入&#34;并且脚本将尝试列表中的第二个单词。

如何模拟按下&#34;输入&#34;在剧本中?

0 个答案:

没有答案