離線安裝expect
expect依賴tcl庫
安裝包:
https://files.cnblogs.com/files/tozh/tcl8.4.11-src.tar.gz
https://files.cnblogs.com/files/tozh/expect-5.43.0.tar.gz
我將兩個壓縮包傳到了/opt/目錄下
1,安裝tcl
tar xf tcl8.4.11-src.tar.gz
cd tcl8.4.11/unix
./configure
make && make install
2,安裝expect
tar xf expect-5.43.0.tar.gz
cd expect-5.43.0
./configure --with-tclinclude=/opt/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/
make && make install
--------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
for i in `cat jisuan_ip`
do
/usr/bin/expect <<-EOF
set time 30
spawn sudo ssh $i
expect "yes/no" { send "yes\r" }
expect "password:"
send "PASSWORD\r"
expect "#" { send " cat /etc/zabbix/zabbix_agented.conf \r" }
expect "#" { send "quit \r" }
EOF
done
#interact