Batch file, Command not working

Tabes

New Member
Joined
Jan 2, 2022
Messages
1
Reaction score
0
Credits
17
Hi together...
I've a Problem to execute some Commands from a Batch File.

Bash:
#!/bin/bash

clear; echo; echo;
sleep 0.25;
   
DOMAIN="$1";
TYPE="selfsigned"
PATH="./traefik/data/certificates";
   
   
if ! [ -z "$DOMAIN" ]; then

    echo "Create private Server Key and Certificate Request..."; echo;

        sudo openssl req -nodes -new -newkey rsa:4096 -keyout $DOMAIN.key -sha256 -out $DOMAIN.csr -config ./cmd/data/openssl.cfg; echo;
         #sudo openssl req -newkey rsa:4096 -sha256 -outform PEM -out server_256.csr -keyout server.key -keyform PEM -days 1825 -nodes;

    if [ "$TYPE" = "selfsigned" ]; then
        echo "Create self signed Certificate..."; echo;
        sudo openssl x509 -req -days 1825 -sha256 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt; echo;
    fi;
else

    echo "###  use...  openssl.sh example.com (selfsigned)                                     ###";
    echo "###  The Option 'selfsigned' will create a selsigned Certificate...                  ###";

fi;
sleep 1.25;

I do start with...
Code:
sudo ./openssl.sh example.com

Result...
Create private Server Key and Certificate Request...
./openssl.sh: line 31: sudo: command not found
Create self signed Certificate...
./openssl.sh: line 36: sudo: command not found
./openssl.sh: line 51: sleep: command not found


Code:
sudo ./openssl.sh
Result...

############################################################
###
### use... openssl.sh example.com (selfsigned)
### The Option 'selfsigned' will create a selsigned Certificate...
###
############################################################

./openssl.sh: line 51: sleep: command not found

openSSL is installed and if I execute it on Command Line, the it works.
The Right to upper Folder is 755 an the File is also 755.

Maybe is any one knowen this Problem?
 
Last edited:


Your problem here is your PATH variable.
$PATH is a special shell variable which stores the paths to system directories containing executables. By overwriting the system's $PATH as a variable in your script, your shell ends up losing the paths to all system executables.
Which is why it says later that it cannot find sleep, or sudo.
Whenever you run your script, the initial clear;echo;echo and sleep commands will run. But as soon as you assign a value to the PATH variable - your shell is completely screwed and will be unable to find any system executables.
I'd recommend changing that variable name from PATH to something like OUTPUTPATH, or literally anything else that describes this variables purpose. Just whatever you do, don't call it PATH!!
e.g.
Bash:
OUTPUTPATH="./traefik/data/certificates";
That should fix your problems!
 

Staff online

Members online


Latest posts

Top