0

新しいサーバーの大規模なグループに一度にパスワードを設定するために使用するスクリプトを期待しています。引数として提供される入力ファイルから読み取ります。あるファイルから変更する必要がある事前設定されたパスワードと、別のファイルから設定する必要があるパスワードを読み取ります。実際には、さまざまな評価を段階的に実行し、発生した内容に基づいて入力を送信します。

set timeout 45
set prompt {\$ $}
set file1 [open [lindex $argv 0] r]
set pw1 [exec cat /home/user/bin/.pw1.txt]
set pw2 [exec cat /home/user/bin/.pw2.txt]

while {[gets $file1 host] != -1} {
    puts $host
    spawn -noecho ssh -q $host
    expect {
        -re $prompt {
            send -- exit\r
            expect eof
        }
        "current" {
            send -- $pw2\r
            expect "New password"
            send -- $pw1\r
            expect "Retype new password"
            send -- $pw1\r
            expect eof
        }
        "continue connecting" {
            send "yes\r"
            expect {
                "current" {
                    send -- $pw2\r
                    expect "New password"
                    send -- $pw1\r
                    expect "Retype new password"
                    send -- $pw1\r
                    expect eof
                }
                -re $prompt {
                    send -- exit\r
                    expect eof
                }
            }
        }
    }
}

puts \r

私が直面している問題は、引数ファイルの最後のホストが更新されないことです。新しいパスワードのプロンプトが表示されます。おそらく、既存のパスワードが送信され、その後に続く 2 つのプロンプトに新しいパスワードが送信されます。ただし、スクリプトの実行後にログインしようとすると、実際にはパスワードが設定されていません。これは、リストの最後のホストでのみ発生します。

私は何が欠けていますか?

編集: スクリプト出力:

opensuse:bin:6476 $ ./host_check.exp hosts_files/cust_host.txt 
SERVER1
You are required to change your password immediately (root enforced)
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user.
Changing password for user.
(current) UNIX password: 
New password: 
Retype new password: SERVER2
You are required to change your password immediately (root enforced)
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user.
Changing password for user.
(current) UNIX password: 
New password: 
Retype new password: SERVER3
You are required to change your password immediately (root enforced)
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user user.
Changing password for user.
(current) UNIX password: 
New password: 
Retype new password: 
opensuse:bin:6477 $ 

編集:「ext_internal 1」を使用したスクリプト出力(サニタイズ済み)

opensuse:bin:6534 $ ./host_check.exp hosts_files/cust_host.txt 
SERVER1
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {16084}
Gate keeper glob pattern for '\$ $' is '\$ '. Activating booster.

expect: does "" (spawn_id exp5) match regular expression "\$ $"? Gate "\$ "? gate=no
"current"? no
"continue connecting"? no
You are required to change your password immediately (root enforced)
Last login: Thu Nov  7 18:55:24 2013 from 10.152.84.124

expect: does "You are required to change your password immediately (root enforced)\r\nLast login: Thu Nov  7 18:55:24 2013 from 10.152.84.124\r\r\n" (spawn_id exp5) match regular expression "\$ $"? Gate "\$ "? gate=no
"current"? no
"continue connecting"? no
WARNING: Your password has expired.
You must change your password now and login again!

expect: does "You are required to change your password immediately (root enforced)\r\nLast login: Thu Nov  7 18:55:24 2013 from 10.152.84.124\r\r\nWARNING: Your password has expired.\r\nYou must change your password now and login again!\r\n" (spawn_id exp5) match regular expression "\$ $"? Gate "\$ "? gate=no
"current"? no
"continue connecting"? no
Changing password for user user.

expect: does "You are required to change your password immediately (root enforced)\r\nLast login: Thu Nov  7 18:55:24 2013 from 10.152.84.124\r\r\nWARNING: Your password has expired.\r\nYou must change your password now and login again!\r\nChanging password for user user.\r\n" (spawn_id exp5) match regular expression "\$ $"? Gate "\$ "? gate=no
"current"? no
"continue connecting"? no
Changing password for user.
(current) UNIX password: 
expect: does "You are required to change your password immediately (root enforced)\r\nLast login: Thu Nov  7 18:55:24 2013 from 10.152.84.124\r\r\nWARNING: Your password has expired.\r\nYou must change your password now and login again!\r\nChanging password for user user.\r\nChanging password for msnyder.\r\n(current) UNIX password: " (spawn_id exp5) match regular expression "\$ $"? Gate "\$ "? gate=no
"current"? yes
expect: set expect_out(0,string) "current"
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) "You are required to change your password immediately (root enforced)\r\nLast login: Thu Nov  7 18:55:24 2013 from 10.152.84.124\r\r\nWARNING: Your password has expired.\r\nYou must change your password now and login again!\r\nChanging password for user user.\r\nChanging password for msnyder.\r\n(current"
send: sending "OldPASS\r" to { exp5 }

expect: does ") UNIX password: " (spawn_id exp5) match glob pattern "New password"? no

New password: 
expect: does ") UNIX password: \r\nNew password: " (spawn_id exp5) match glob pattern "New password"? yes
expect: set expect_out(0,string) "New password"
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) ") UNIX password: \r\nNew password"
send: sending "NewPASS" to { exp5 }

expect: does ": " (spawn_id exp5) match glob pattern "Retype new password"? no


expect: does ": \r\n" (spawn_id exp5) match glob pattern "Retype new password"? no
Retype new password: 
expect: does ": \r\nRetype new password: " (spawn_id exp5) match glob pattern "Retype new password"? yes
expect: set expect_out(0,string) "Retype new password"
expect: set expect_out(spawn_id) "exp5"
expect: set expect_out(buffer) ": \r\nRetype new password"
send: sending "NewPASS" to { exp5 }

私はそのオプションをオンにしたことがないので、これをすべて解釈する方法がわかりません。それは十分に単純に見えますが、私の知識を超えているいくつかのビットがあります.

4

0 に答える 0