0

The following python script:

def run_build(path):
    cmd = path + '/build.sh'
    p = subprocess.call(cmd)

The following bash script exec two another scripts:

#!/bin/bash
cd "${0%/*}"
echo $(./create_env.sh)
echo $(./set_webhook.sh)
echo $(docker-compose up -d --build)

create_env.sh:

#!/bin/bash
PORT=$(comm -23 <(seq 7000 8000 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep "[0-9]\{1,5\}" | sort -u) | head -n 1)
MONGODB_PORT=$(comm -23 <(seq 27017 27100 | sort) <(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep "[0-9]\{1,5\}" | sort -u) | head -n 1)

destdir=$PWD/.env
echo >> "$destdir"
echo "APP_PORT=$PORT" >> "$destdir"
echo "MONGODB_PORT=$MONGODB_PORT" >> "$destdir"

The output is:

Path: /home/navka/Environments/teststartupservicebot/build.sh
./create_env.sh: line 2: head: command not found
./create_env.sh: line 2: comm: command not found
./create_env.sh: line 2: seq: command not found
...

Where is my problem? Thanks!

3
  • Your script doesn't need the command substitutions. Just use ./create_env.sh in stead of echo $(./create_env.sh), etc. Commented Jan 4, 2020 at 14:54
  • This isn't a complete example: what prints Path: ...? That's probably where the problem likes. You didn't use the variable PATH for your own purposes, did you? Commented Jan 4, 2020 at 14:56
  • @chepnerI didn't use PATH Commented Jan 4, 2020 at 16:52

1 Answer 1

1

I would say your first step would be to place:

echo $PATH

as the first line following the #!/bin/bash shebang line in create_env.sh, to ensure the path is set up.

Make sure it contains the directory for those executables (probably /usr/bin), which you can probably find out by executing (for example) which comm or where comm from a command line.

If it doesn't contain the relevant directory, that explains why it cannot find the executables. In that case, you will need to discover why they're not there.

Perhaps the simplest fix would be to just add something like:

PATH="${PATH}:/usr/bin"

to your environment setup script. This will ensure the path does have the relevant entry.


And, as an aside, if those lines in build.sh are meant to be cumulative (so, for example, set_workbook requires the environment changes made by create_env, you should be aware that these are currently run in sub-shells, meaning changes from one will not persist after the sub-shell exits.

That's not necessarily the case as you persist them to a file, which may be read by the subsequent steps.

If you do need the changes in the environment for subsequent steps (as opposed to a file), you will need to source them in the context of the current shell, such as with:

. ./create_env.sh

As I said, this may not be necessary but you may want to look into it, just in case.

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

6 Comments

Thanks for your reply! echo $PATH print /home/navka/Environments/service-startup-bot/env/bin, so the path is set up.
Also, you right, those lines in build.sh are meant to be cumulative and I don't need to change my enviroment variables, only .env file
@KateGurman PATH should have far more directories that that in it: /bin, /usr/bin, etc.
@Kate, the pathis is set up but it's almost certainly set up wrongly :-) The comm/seq/head executables are probably in /usr/bin and all you have in the path is that service-startup bin directory. That's not enough.
@paxdiablo so, what I need to do?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.