0

I have a Shellscript that starts a python command (taken from HERE)

#!/bin/sh

COMMAND='cd /sc2ai/agent && python3 myscript.py'
LOGFILE=restart.txt

writelog() {
  now=`date`
  echo "$now $*" >> $LOGFILE
}

writelog "Starting"
while true ; do
  $COMMAND
  writelog "Exited with status $?"
  writelog "Restarting"
done

I would like this script to be executed immediately after the Container is loaded and I am doing it like this: (the very last lines of my Dockerfile)

# Run Apache
CMD apachectl -D FOREGROUND

# Start the Agent
RUN chmod +x agent.sh
ENTRYPOINT ["/bin/bash", "./agent.sh"]

The builds, but upon starting (docker-compose up -d --build && winpty docker-compose run sc2 bash) it creates this error:

./agent.sh: line 2: $'\r': command not found

./agent.sh: line 5: $'\r': command not found

./agent.sh: line 6: syntax error near unexpected token `$'{\r''

'/agent.sh: line 6: `writelog() {

What am I doing wrong?

Community
  • 1
  • 1
PrimuS
  • 2,505
  • 6
  • 33
  • 66
  • 1
    try `dos2unix agent.sh` or change your End of line from windows to linux/unix format. you can change it from any editor as well. multiple ways to do it: https://stackoverflow.com/q/11616835/2987755 – dkb Jan 08 '19 at 08:53
  • Do you have carriage return characters in your shell script? Line endings should be represented only by line feed characters. – Henry Jan 08 '19 at 08:53
  • 1
    Thanks, the `dos2unix` did the trick. Bonus Question, why do I get `./agent.sh: line 13: cd: too many arguments` now? – PrimuS Jan 08 '19 at 09:06

0 Answers0