2013-06-25 50 views
0

期望在提示用戶憑證而不是指定變量($ user)時發送$ expect_out(buffer)。然後它超時。下面是代碼:

... 
    } 
    "yes" { 
     send_user "\nEnter your username for the WLC supporting the new APs:\n" 
     sleep 6 
    } 
} 
expect { 
    -re "(.*)\n" { 
     set user $expect_out(1,string) 
    } 
} 
send_user "\nEnter your password for the WLC supporting the new APs:\n" 
sleep 15 
expect { 
    -re "(.*)\n" { 
     set pass $expect_out(1,string) 
    } 
} 
sleep 1 
send_user "\nSshing to the IP of the WLC supporting the new APs ($wlc_temp)\n" 
spawn ssh $wlc_temp 

expect { 
    "User:" { 
     send $user\n 
     sleep 1 
    } 
} 
expect { 
    "assword:" { 
     send $pass\n 
     sleep 1 
    } 
} 

下面是結果:

(設備主機名)用戶:(設備主機名) 用戶:

以下是在(1)調試:

Sshing到支持新接入點的WLC的IP() spawn ssh 父:等同步字節 父:告訴孩子先走 父:現在從兒童產卵不同步:返回{} 7153

想到:不「」(spawn_id在exp6)匹配glob模式「用戶:」?否

expect:「\ r \ n」(spawn_id exp6)是否匹配glob模式「User:」?沒有 (設備主機名)用戶:

期望:「\ r \ n(device hostname)用戶:」 (spawn_id exp6)匹配glob模式「User:」?是的 expect:set expect_out(0,string)「用戶:」expect:設置expect_out(spawn_id)「exp6」 expect:設置expect_out(緩衝區)「\ r \ n(設備主機名)用戶:」 send: \ n「到{exp6}

expect:」「(spawn_id exp6)是否匹配glob模式」assword:「?沒有

(設備主機名)用戶:

預計有:不爲 「\ r \ n(設備主機)用戶:」(spawn_id在exp6)匹配的glob 圖案 「assword:」?沒有 預計有:超時

更新: 搬遷請求用戶輸入到腳本的頂部的語句擔任周圍的工作。

回答

1

當你想讀取用戶的輸入,你應該使用expect_user而不是expect

 send_user "\nEnter your username for the WLC supporting the new APs:\n" 
     sleep 6 
    } 
} 
expect_user { 
    -re "(.*)\n" { 
     set user $expect_out(1,string) 
    } 
} 
send_user "\nEnter your password for the WLC supporting the new APs:\n" 
sleep 15 
expect_user { 
    -re "(.*)\n" { 
     set pass $expect_out(1,string) 
    } 
} 
sleep 1 
send_user "\nSshing to the IP of the WLC supporting the new APs ($wlc_temp)\n" 

# ... 

(我也認爲你可以使用有較少的sleep電話,而不僅僅是調補超時,但這不太可能對腳本的正確操作產生影響。)

+0

我做了您推薦的更改,但仍然看到相同的行爲。 – user1933231