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

36
sftp.go
View File

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

20
ssh.go
View File

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

View File

@ -1,7 +1,31 @@
package main
import "time"
import (
"fmt"
"os"
"path/filepath"
"time"
)
func timeToString(currentTime time.Time) 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
}