In Linux, how does one use shell scripts to capture remote logs? There is a dilemma in analyzing online logs. There are too many machines. It is unrealistic to log on to each server, but it is more troublesome to download the logs because each SCP requires a password. So I wrote a script to automatically capture remote logs to implement basic functions.
Code:
#! /Usr/bin/CT-F
If {$ argc! = 1 & $ argc! = 2 }{
Send_user "no remote log file name entered. \ n"
Send_user "Format: Get. Sh $ {remote_log }$ {local_log} \ n"
Send_user "Example: \ n"
Send_user "./get. sh/home/admin/log/GC. log/tmp/GC. log \ n"
Send_user "local_log is not input. Default Value:/logs/log.txt \ n"
Exit
} # Www.jbxue.com
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 is not input. The default path is local log: $ local_logpath \ n"
}
Set File "./ip.txt"
If {[file isfile $ file]! = 1 }{
Send_user "the IP file does not exist. Please check. \ n"
Exit
}
Send_user "\ n"
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 [email protected] $ IPS ($ I): $ log_path $ local_logpath. $ IPS ($ I)
Reset CT "[email protected] $ IPS ($ I)'s password:" {send "look \ r "}
CT EOF
Incr I
}
Exit