2016-09-21 25 views
-1

當談到Expect時,我是一個新手,我想我會先試着在我的本地機器上嘗試一下,讓自己的腳溼潤。爲Linux「adduser」命令創建一個Expect腳本

爲此,我想我會嘗試運行Expect反對「adduser」命令。

我無法讓它正常工作,好像一切正​​常運行,我能夠到達最後一個提示,並且它確實退出,但用戶仍然未創建。

我在做什麼錯?

#/usr/bin/expect -f 
spawn adduser testuser 

expect "Enter new UNIX password" 
send "testpassword\r" 

expect "Retype new UNIX password" 
send "testpassword\r" 

expect "  Full Name []: " 
send "\r" 

expect "  Room Number []: " 
send "\r" 

expect "  Work Phone []: " 
send "\r" 

expect "  Home Phone []: " 
send "\r" 

expect "  Other []: " 
send "\r" 

expect "Is the information correct? \[Y/n\] " 
send "\r" 
+0

最後加上'expect eof'。 – Dinesh

+0

用'expect -d scriptname'運行腳本並仔細閱讀調試輸出:所有模式匹配嗎? –

回答

0

貌似這一切都是錯誤的:expect " Something []: "

我會用expect -ex {Something []: }

    使用「精確」匹配,因爲你不需要的水珠或正則表達式模式的功率
  1. ,和
  2. 大括號確保括號不被解釋爲Tcl命令替換語法。