Shell command - python script in bash script does not receive arguments

[SOLVED] simple extra arguement that should not have been there.

I have a Hass script that calls a shell command which calls a bash script which calls a python script, which is failing.

if I comment everything out of the bash script except the python line, I can trigger it from HASS.
So the bash script and HASS config is correct.

If I call the same bash script directly from the terminal, everything works.

if I try the full workflow I get an error in HASS, simply saying failed.

going back to my bash script and adding “&>> file” to the end I can see an error message I made in the python script meaning the arguments are wrong/invalid/missing.

HASS config:

  start_projector: /bin/bash /home/homeassistant/.homeassistant/scripts/

    alias: Star Projector
      - service: shell_command.start_projector

bash script:


export DISPLAY=:0
/usr/bin/python2.7 /home/homeassistant/.homeassistant/scripts/ -i -p 9999 -m "POWER" -v &>> /home/homeassistant/log.txt

python script:

........some stuff...............

        opts, args = getopt.getopt(sys.argv[1:],"i:p:m:",["ip=:","port=:","msg=:"])
except getopt.GetoptError:
        print ("Failed to supply: -i <projectorIPaddress> -p <port> -m <message>")
for opt, arg in opts:

........some stuff...............

log file:

Failed to supply: -i <projectorIPaddress> -p <port> -m <message>

have you tried to amend your bash script to look like this:

test=$(/usr/bin/python2.7 /home/homeassistant/.homeassistant/scripts/ -i -p 9999 -m "POWER" -v &>> /home/homeassistant/log.txt)

I don’t remember if it does this, but is getopt complaining that the -v is not understood?

That didn’t work.

I tried:

echo $test >> log

and all I got was

Failed need to supply: -i <projectorIPaddress> -p <port> -m <message> 

followed by a blank line

test would normally get the command result, it’s not a variable to use and run.
It was worth a shot :wink:

you might be on to something here.
the -v is not meant to be there, that was me trying to figure out which python I was using.
original command was just

I was expecting a 1 (or 0)

disclaimer: self taught linux, this is my first time with python

yep, solved. Thank you for pointing this out.

1 Like