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:
parent
3871351ace
commit
dfbcce84ae
22
sftp.go
22
sftp.go
@ -8,16 +8,12 @@ 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) []*os.File {
|
||||
homedir, _ := os.UserHomeDir()
|
||||
var dstFiles []*os.File
|
||||
|
||||
func (s SSHConnection) getFile(client *ssh.Client) {
|
||||
for _, j := range s.Logs {
|
||||
sftp, err := sftp.NewClient(client)
|
||||
//var srcFile []*os.File
|
||||
//var dstFile []*os.File
|
||||
|
||||
if err != nil {
|
||||
fmt.Errorf("Error")
|
||||
@ -25,8 +21,7 @@ func (s SSHConnection) getFile(client *ssh.Client) {
|
||||
|
||||
defer sftp.Close()
|
||||
|
||||
for _, j := range s.Logs {
|
||||
srcFile, err := sftp.Open(srcPath + j)
|
||||
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
|
||||
}
|
||||
|
16
ssh.go
16
ssh.go
@ -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)
|
||||
|
||||
err := gzipit(homedir+filename, ".")
|
||||
slashed := s.getFile(j)
|
||||
for _, k := range slashed {
|
||||
name := osfileToSting(k)
|
||||
err := gzipit(homedir+"/"+name, ".")
|
||||
|
||||
if err != nil {
|
||||
fmt.Errorf("Cannot gzip file(s)", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return sftp
|
||||
}
|
||||
|
||||
func (s SSHConnection) gzipItUp() {
|
||||
// TODO: placeholder function??
|
||||
}
|
||||
|
26
string.go
26
string.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user