0

I wrote a small script for running a network vulnerability tool but it doesn't seem to be outputting to the file path I want it to. Can someone point out where I went wrong?

     cisco-torch -A 192.168.128.1 -l v > ~/Documents/Network Scanning Logs/ciscotorchlogs/ciscotorchlogs$(date+"%Y_%m_%d_%I_%M_%p")logfile.txt

Ideally the script is supposed to run and create a new file names ciscotorchlogs(date)logfile.txt and put its output in there. I ran the script overnight but I came back this morning and found it had not created any output files.

Thanks for the help.

2 Answers2

0

Your path is ~/Documents/Network Scanning Logs and I suspect those whitespaces are causing issues. You can escape thus:

~/Documents/Network\ Scanning\ Logs

etc.

Note also that > is redirecting stdout. You likely want stderr as well, and so I would use

> file.txt 2>&1

to send stderr to the stdout stream (and hence be redirected to, say, file.txt)

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

The redirection was to a file named Network in the Documents folder because you didn't quote or escape the whitespace. The tokens after the first whitespace will have been passed on as parameters to your command.

With proper quoting, the command would be

cisco-torch -A 192.168.128.1 -l v > ~/"Documents/Network Scanning Logs/ciscotorchlogs/ciscotorchlogs$(date +"%Y_%m_%d_%I_%M_%p")logfile.txt"

Notice how ~ must not be quoted, and how a command substitution within double quotes still gets expanded. (Single quotes would pass the text within the quotes completely verbatim.) Finally, there needs to be a space between the date command and its argument.

If you also want to capture standard error, you can add another redirection 2>&1 at the end (again, with a space before it).

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks that was exactly what I needed to fix this issue it also helped me find some case sensitivity bugs. I've corrected it and its now outputting properly. – mike davidson Jan 08 '20 at 16:14