0

i have a docker-compose.yml file and when i run it ,it run a sh script. In sh script i have $SECONDS to count the seconds upto 120 seconds.It works as expected when I run it from command line. I was trying to achieve the same effect using docker container.

echo "right before second"                                                                                                                                                                                
echo $SECONDS                                                                                                                                                                                             
echo "right after second"                                                                                                                                                                                 
                                                                                                                                                                                                          
  interval=10                                                                                                                                                                                             
  ##((end_time = ${SECONDS} + 120)) 
         while ((${SECONDS} < 120)); do
            SuccessMessage=$(grep "successful" $LOG_FILE | wc -l)
            # cmd=$?
            if [ $SuccessMessage -gt 0 ]; then
              echo "Successful"
              exit 0
            fi
            echo "Waiting..."
            sleep ${interval}
          done
        echo " Failed to Start"
      exit 1

when i run it in docker it's not printing echo message , its giving me this.

mui-MetaLibrary-1  | right before second
mui-MetaLibrary-1  | 
mui-MetaLibrary-1  | right after second
mui-MetaLibrary-1  | /opt/app/zuulStartContainer.sh: line 26: can't open 120: no such file

nothing is printing in $SECONDS . can someone tell how can i print SECONDS while running in docker

pja
  • 3
  • 4
  • In the container, what is the shell? (i.e. bash? sh?) What version? – glenn jackman Jul 13 '22 at 23:41
  • It looks like the environment variable `$SECONDS` isn't being defined as anything. Do you have an assignment, or a Compose `environment:` block, or something else that's supposed to define it? – David Maze Jul 13 '22 at 23:50
  • It's the sh , version i am not sure as i am new in this, where can i check for it? – pja Jul 27 '22 at 04:47
  • The $SECONDS doesn't needs to be defined , it's purpose is to count the seconds from where it gets activated or smth, Please refer this article https://www.oreilly.com/library/view/shell-scripting-expert/9781118166321/c03-anchor-3.xhtml – pja Jul 27 '22 at 04:49

0 Answers0