Merge branch '9683e88' of wymiller/logman into master

This commit is contained in:
Wyatt J. Miller 2019-08-20 01:50:20 +00:00 committed by Gogs
commit 854270f99c
6 changed files with 17 additions and 15 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
config.yaml config.yaml
.vscode/ .vscode/
vendor/ vendor/
*.log
*.tar.gz

View File

@ -1,6 +1,6 @@
package main package main
import "fmt" import "log"
func main() { func main() {
config := initializeConfig("config.yaml") config := initializeConfig("config.yaml")
@ -8,5 +8,5 @@ func main() {
clientConns := sshConn.dialConnection(sshConfig) clientConns := sshConn.dialConnection(sshConfig)
_ = sshConn.openSession(clientConns) _ = sshConn.openSession(clientConns)
success := sshConn.executeSFTP(clientConns) success := sshConn.executeSFTP(clientConns)
fmt.Println(success) log.Println(success)
} }

13
sftp.go
View File

@ -3,20 +3,18 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/pkg/sftp" "github.com/pkg/sftp"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
) )
var ( var (
dstPath string = "/root/" dstPath string = "/home/wyatt/"
srcPath string = "/var/log/" srcPath string = "/var/log/"
filename string = "dmesg" filename string = "dpkg.log"
) )
func getFile(client *ssh.Client) { func getFile(client *ssh.Client) {
t := time.Now()
sftp, err := sftp.NewClient(client) sftp, err := sftp.NewClient(client)
if err != nil { if err != nil {
@ -33,8 +31,7 @@ func getFile(client *ssh.Client) {
defer srcFile.Close() defer srcFile.Close()
timeResult := timeToString(t) dstFile, err := os.Create(dstPath + filename)
dstFile, err := os.Create(dstPath + filename + timeResult)
if err != nil { if err != nil {
fmt.Errorf("FUCK") fmt.Errorf("FUCK")
@ -44,7 +41,3 @@ func getFile(client *ssh.Client) {
srcFile.WriteTo(dstFile) srcFile.WriteTo(dstFile)
} }
func timeToString(currentTime time.Time) string {
return currentTime.String()
}

2
ssh.go
View File

@ -96,7 +96,7 @@ func (s SSHConnection) executeSFTP(execute SSHClients) SSHSFTP {
// TODO: this is just a placeholder, change to the actual tarring executable // TODO: this is just a placeholder, change to the actual tarring executable
getFile(j) getFile(j)
err := gzipit("/root/"+filename, ".") err := gzipit("/home/wyatt/"+filename, ".")
if err != nil { if err != nil {
fmt.Errorf("Cannot gzip file(s)", err) fmt.Errorf("Cannot gzip file(s)", err)

7
string.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "time"
func timeToString(currentTime time.Time) string {
return currentTime.String()
}

2
tar.go
View File

@ -42,7 +42,7 @@ func gzipit(source string, target string) error {
return err return err
} }
func ungzipit(source string, target string) { func gunzipit(source string, target string) {
reader, err := os.Open(source) reader, err := os.Open(source)
if err != nil { if err != nil {