0

For some reason, running docker commands from bash scripts doesn't work if you add regular variables, example:

c=$(date +"%x")
targets="www.example.com"

docker build -t amass https://github.com/OWASP/Amass.git
docker run amass --passive -d $targets > $c.txt

The error is as follows:

./main.sh: 13: ./main.sh: cannot create 12/29/2018.txt: Directory nonexistent

Running same commands from a terminal operate directly. How can I fix this?

5
  • 2
    Btw: sh is not bash. Commented Dec 29, 2018 at 13:54
  • Can you show main.sh ? Do you have a directory amass_out_12/29 in your docker? Commented Dec 29, 2018 at 13:55
  • mkdir amass_out_12/29? Commented Dec 29, 2018 at 13:58
  • Updating main post to full script. I don't have that directory in my docker, this should stdout to my host - or should it? (also - its a file not a directoryooooooo! I just realized the numbers of the date.time now may be interpreted as folders!). Commented Dec 29, 2018 at 14:01
  • 3
    Yes, change the date format, e.g. c=$(date +"%d-%m-%y") otherwise it means subdirectories. Also, as @Cyrus highlighted in the first comment, it's always good to write the shebang as first line of your scripts, so you are sure about the script intepreter to use ( #!/bin/bash that differs from #!/bin/sh ) Commented Dec 29, 2018 at 14:12

1 Answer 1

1

In your situation, it is too dangerous to use the %x option of date, which stands for:

%x locale's date representation (e.g., 12/31/99)

You wouldn't control anything, and may have various behaviour between your testing computer, and the docker, if the locale is different.

Anyway, using date format with slash '/', which are going to be interpreted as directory separator will lead to issue.

For both reasons, you should define the format of your date.

For instance:

#!/bin/bash

c=$(date +'%Y-%m-%d-%H-%M-%S')
targets="www.example.com"

docker build -t amass https://github.com/OWASP/Amass.git
docker run amass --passive -d $targets > $c.txt

You should add as many information (hour, minute, second ...) in your date as you think you may run your script; otherwise, the output of previous run will be overriden.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.