#!/usr/bin/expect -f
# 自动发送密码抓取远程日志
# 整理:
www.jb200.com
#
if { $argc !=1 &&  $argc !=2  } { 
send_user "没有输入远程日志文件名.n" 
send_user "格式是:get.sh ${remote_log} ${local_log}n" 
send_user "例如:n" 
send_user "./get.sh /home/admin/log/gc.log /tmp/gc.logn" 
send_user "local_log没有输入,默认是值:/logs/log.txtn" 
exit 
} 
set log_path [lindex $argv 0] 
if { $argc == 2 } { 
    set local_logpath [lindex $argv 1] 
} else { 
    set local_logpath "./logs/log.txt" 
send_user "local_log没有输入,默认是本地日志路径 :$local_logpath n" 
} 
set file "./ip.txt" 
if {[file isfile $file]!=1} { 
    send_user "Ip 文件不存在,请检查.n" 
    exit 
} 
send_user "nnn" 
set f [open $file r] 
set count 0 
while {[gets $f line]>=0} { 
set ips($count) $line 
#puts "line $count of file: $ips($count)" 
incr count 
} 
close $f 
set i 0 
while {$i<50} { 
#puts $ips($i) 
spawn scp nobody@$ips($i):$log_path  $local_logpath.$ips($i)    
expect "nobody@$ips($i)'s password: " {send "lookr"} 
expect eof 
incr i 
} 
exit