diff --git a/sftp.go b/sftp.go index d0cbc64..589b406 100644 --- a/sftp.go +++ b/sftp.go @@ -14,30 +14,34 @@ var ( filename string = "dpkg.log" ) -func getFile(client *ssh.Client) { +func (s SSHConnection) getFile(client *ssh.Client) { sftp, err := sftp.NewClient(client) + //var srcFile []*os.File + //var dstFile []*os.File if err != nil { - fmt.Errorf("FUCK") + fmt.Errorf("Error") } defer sftp.Close() - srcFile, err := sftp.Open(srcPath + filename) + for _, j := range s.Logs { + srcFile, err := sftp.Open(srcPath + j) - if err != nil { - fmt.Errorf("FUCK") + if err != nil { + fmt.Errorf("Error") + } + + defer srcFile.Close() + + dstFile, err := os.Create(dstPath + j) + + if err != nil { + fmt.Errorf("Error") + } + + defer dstFile.Close() + srcFile.WriteTo(dstFile) } - defer srcFile.Close() - - dstFile, err := os.Create(dstPath + filename) - - if err != nil { - fmt.Errorf("FUCK") - } - - defer dstFile.Close() - - srcFile.WriteTo(dstFile) } diff --git a/ssh.go b/ssh.go index d5ce94f..ca0289d 100644 --- a/ssh.go +++ b/ssh.go @@ -18,6 +18,7 @@ type SSHConnection struct { Password string Port int Hosts []string + Logs []string } type SSHClients []*ssh.Client @@ -39,6 +40,7 @@ func initializeConnection(config Configuration) (*SSHConnection, *ssh.ClientConf Password: config.Password, Port: config.Port, Hosts: config.Hosts, + Logs: config.Logs, } sshConfig := &ssh.ClientConfig{ @@ -96,7 +98,7 @@ func (s SSHConnection) executeSFTP(execute SSHClients) SSHSFTP { for _, j := range execute { // TODO: this is just a placeholder, change to the actual tarring executable - getFile(j) + s.getFile(j) err := gzipit(homedir+filename, ".") diff --git a/todo.md b/todo.md index 4471f18..20e34a3 100644 --- a/todo.md +++ b/todo.md @@ -4,4 +4,6 @@ - Allow fetching of multiple log files (fields under the defined host? Seperate key/field? Dynamic?) - Allow different machines to collect different log files - Allow to gather directories of log files -- Develop a log getting logs for sanity \ No newline at end of file +- Develop a log getting logs for sanity + +Developing a way to include a log space in the config which this program does not have. \ No newline at end of file