-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48518f6
commit b466c4c
Showing
2 changed files
with
37 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package befehl | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/sgsullivan/befehl/helpers/filesystem" | ||
) | ||
|
||
func (instance *Instance) prepareLogDir() error { | ||
logDir := instance.getLogDir() | ||
if !filesystem.PathExists(logDir) { | ||
if err := os.MkdirAll(logDir, os.FileMode(0700)); err != nil { | ||
return fmt.Errorf("failed creating [%s]: %s", logDir, err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (instance *Instance) logPayloadRun(host string, output string) error { | ||
instance.prepareLogDir() | ||
logFilePath := instance.getLogFilePath(host) | ||
|
||
logFile, err := os.Create(logFilePath) | ||
if err != nil { | ||
return fmt.Errorf("error creating [%s]: %s", logFilePath, err) | ||
} | ||
defer logFile.Close() | ||
|
||
if _, err = logFile.WriteString(output); err != nil { | ||
return fmt.Errorf("error writing to [%s]: %s", logFilePath, err) | ||
} | ||
|
||
log.Printf("payload completed on %s! logfile at: %s\n", host, logFilePath) | ||
return nil | ||
} |