Issue
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.
Solution
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).
Answered By - tripleee