adding multiple logs is now live

Now, you can add multiple logs within the configuration file,
which is really cool, if you need multiple logs off of machines
in one go round. Please note that you'll have to enter absolute
paths for each log to get transferred.
This commit is contained in:
Wyatt J. Miller 2019-09-28 00:32:20 -04:00
parent 3871351ace
commit dfbcce84ae
3 changed files with 51 additions and 31 deletions

22
sftp.go
View File

@ -8,16 +8,12 @@ import (
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
) )
var ( func (s SSHConnection) getFile(client *ssh.Client) []*os.File {
dstPath string = "/home/wyatt/" homedir, _ := os.UserHomeDir()
srcPath string = "/var/log/" var dstFiles []*os.File
filename string = "dpkg.log"
)
func (s SSHConnection) getFile(client *ssh.Client) { for _, j := range s.Logs {
sftp, err := sftp.NewClient(client) sftp, err := sftp.NewClient(client)
//var srcFile []*os.File
//var dstFile []*os.File
if err != nil { if err != nil {
fmt.Errorf("Error") fmt.Errorf("Error")
@ -25,8 +21,7 @@ func (s SSHConnection) getFile(client *ssh.Client) {
defer sftp.Close() defer sftp.Close()
for _, j := range s.Logs { srcFile, err := sftp.Open(j)
srcFile, err := sftp.Open(srcPath + j)
if err != nil { if err != nil {
fmt.Errorf("Error") fmt.Errorf("Error")
@ -34,7 +29,9 @@ func (s SSHConnection) getFile(client *ssh.Client) {
defer srcFile.Close() defer srcFile.Close()
dstFile, err := os.Create(dstPath + j) h := slashSeperator(j)
dstFile, err := os.Create(homedir + "/" + h)
if err != nil { if err != nil {
fmt.Errorf("Error") fmt.Errorf("Error")
@ -42,6 +39,9 @@ func (s SSHConnection) getFile(client *ssh.Client) {
defer dstFile.Close() defer dstFile.Close()
srcFile.WriteTo(dstFile) srcFile.WriteTo(dstFile)
dstFiles = append(dstFiles, dstFile)
} }
return dstFiles
} }

16
ssh.go
View File

@ -94,23 +94,19 @@ func (s SSHConnection) openSession(client SSHClients) SSHSessions {
func (s SSHConnection) executeSFTP(execute SSHClients) SSHSFTP { func (s SSHConnection) executeSFTP(execute SSHClients) SSHSFTP {
// execute order 66 lol // execute order 66 lol
sftp := SSHSFTP{} sftp := SSHSFTP{}
homedir := os.Getenv("HOME") homedir, _ := os.UserHomeDir()
for _, j := range execute { for _, j := range execute {
// TODO: this is just a placeholder, change to the actual tarring executable slashed := s.getFile(j)
s.getFile(j) for _, k := range slashed {
name := osfileToSting(k)
err := gzipit(homedir+filename, ".") err := gzipit(homedir+"/"+name, ".")
if err != nil { if err != nil {
fmt.Errorf("Cannot gzip file(s)", err) fmt.Errorf("Cannot gzip file(s)", err)
} }
}
} }
return sftp return sftp
} }
func (s SSHConnection) gzipItUp() {
// TODO: placeholder function??
}

View File

@ -1,7 +1,31 @@
package main package main
import "time" import (
"fmt"
"os"
"path/filepath"
"time"
)
func timeToString(currentTime time.Time) string { func timeToString(currentTime time.Time) string {
return currentTime.String() return currentTime.String()
} }
func osfileToSting(currentOsFile *os.File) string {
file, err := os.Open(currentOsFile.Name())
fileinfo, err := file.Stat()
if err != nil {
fmt.Printf("Heyo, there's no file here!\n")
}
name := fileinfo.Name()
return name
}
func slashSeperator(unslashed string) string {
s := unslashed
_, file := filepath.Split(s)
return file
}