1. 程式人生 > >用shell指令碼批量分發公鑰,實現用…

用shell指令碼批量分發公鑰,實現用…

用shell指令碼批量分發公鑰(將所有),先建立金鑰分發expetc指令碼key.exp 再建立shell指令碼,呼叫expetc 1.vim ip.txt 10.1.1.1 10.2.2.2 10.3.3.3 2.key.exp vim key.exp #!/usr/bin/expetc set timeout 300 set password "redhat" set ip [lindex $argv 0] spawn ssh-copy-id [email protected]$ip expetc{ "yes/no"{ send "yes\r" exp_continue } "password: "{ send"password\r" exp_continue } eof; } 再建立shell指令碼,呼叫expetc 3. vim distribute.exp #!/bin/bash ./etc/init.d/functions for i in 'cat /root/ip.txt';do expetc /root/key.exp $i>/dev/null 2>&1 if[$? -eq 0];then action"$i" /bin/true else action "$i"/bin/false fi done