diff --git a/src/config.go b/src/config.go index 361928b..8b2509d 100644 --- a/src/config.go +++ b/src/config.go @@ -4,7 +4,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "dario.cat/mergo" "gopkg.in/yaml.v3" @@ -29,7 +29,7 @@ type Device struct { } func readYAMLFile(path string) (map[string]interface{}, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/src/main.go b/src/main.go index 7e6730d..ba195b0 100644 --- a/src/main.go +++ b/src/main.go @@ -217,7 +217,9 @@ func main() { rootCmd.Flags().StringSliceVar(&hostFilter, "host", []string{}, "Specific host(s) to process (can be repeated, processes all if not specified)") rootCmd.Flags().IntVar(¶llel, "parallel", 10, "Maximum number of devices to process in parallel") - rootCmd.MarkFlagRequired("yaml") + if err := rootCmd.MarkFlagRequired("yaml"); err != nil { + log.Fatal(err) + } if err := rootCmd.Execute(); err != nil { log.Fatal(err) diff --git a/src/ssh.go b/src/ssh.go index 9fb82c6..d4a6e15 100644 --- a/src/ssh.go +++ b/src/ssh.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -145,11 +144,11 @@ func (rb *RouterBackup) Connect() error { } } - key, err := ioutil.ReadFile(keyFile) + key, err := os.ReadFile(keyFile) if err == nil { signer, err := ssh.ParsePrivateKey(key) if err != nil { - fmt.Errorf("unable to parse private key: %v", err) + fmt.Printf("%s: Unable to parse private key: %v\n", rb.hostname, err) } else { config.Auth = append(config.Auth, ssh.PublicKeys(signer)) } @@ -268,7 +267,10 @@ func (rb *RouterBackup) BackupCommands(commands []string, excludePatterns []stri fmt.Fprintf(file, "## COMMAND: %s\n", command) filteredOutput := filterOutput(output, excludePatterns) - file.WriteString(filteredOutput) + if _, err := file.WriteString(filteredOutput); err != nil { + fmt.Printf("%s: Failed to write output: %v\n", rb.hostname, err) + hasErrors = true + } file.Close() successCount++