1. go does not work with node.execute API

go does not work with node.execute API

Home Forums FABRIC General Questions and Discussion go does not work with node.execute API

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4006
    Xusheng Ai
    Participant

      Hello,

      I tried to install go and yanfd before I ssh to the node. I did that by the following code:

      
      try:
          for node in slice.get_nodes():
              stdout, stderr = node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz"')
              stdout, stderr = node.execute('tar -xf "go1.19.5.linux-amd64.tar.gz"')              
              stdout, stderr = node.execute('sudo mv -v go /usr/local')
              stdout, stderr = node.execute('echo "export GOPATH=$HOME/go" >> ~/.bashrc')
              stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc')
              stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc')
              stdout, stderr = node.execute('go install github.com/named-data/YaNFD/cmd/yanfd@latest')  
              
      except Exception as e:
          print(f"Exception: {e}")

      I got the error that bash: go: command not found. However, I could use go as I ssh to the node. I was wondering what might cause this error.

      Thanks,
      Best Regards,
      Xusheng

      • This topic was modified 12 months ago by Xusheng Ai.
      #4008
      Xusheng Ai
      Participant

        This is the updated code but it still does not work with the same error:

        try:
            for node in slice.get_nodes():
                stdout, stderr = node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz"')
                stdout, stderr = node.execute('tar -xf "go1.19.5.linux-amd64.tar.gz"')              
                stdout, stderr = node.execute('sudo mv -v go /usr/local')
                stdout, stderr = node.execute('echo "export GOPATH=$HOME/go" >> ~/.bashrc')
                stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc')
                stdout, stderr = node.execute('echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc')
                stdout, stderr = node.execute('source ~/.bashrc')
                stdout, stderr = node.execute('go install github.com/named-data/YaNFD/cmd/yanfd@latest')  
                
        except Exception as e:
            print(f"Exception: {e}")
        • This reply was modified 12 months ago by Xusheng Ai.
        #4019
        Paul Ruth
        Keymaster

          Each of those execute calls creates a separate ssh session that runs the the command.  This means that each of the calls runs in its own shell and the result of any pervious ‘export’ or ‘source’ calls will not be represented in the environment of a new call.

          In this case you are putting everything in the .bashrc file, so I would think that the new call would source the .bashrc file when the shell is created but maybe there is some other piece of the environment  missing.

          Try putting that all in one call, something like this:

          node.execute('curl -O -L "https://golang.org/dl/go1.19.5.linux-amd64.tar.gz" ;'
                        'tar -xf "go1.19.5.linux-amd64.tar.gz" ;'
                        'sudo mv -v go /usr/local ;'
                        'echo "export GOPATH=$HOME/go" >> ~/.bashrc ;' 
                        'echo "export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin" >> ~/.bashrc ;' 
                        'echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc ;' 
                        'source ~/.bashrc ;' 
                        'go install github.com/named-data/YaNFD/cmd/yanfd@latest')
          
          
          #4026
          Justin Presley
          Participant

            Hi, I tried the provided remedy which lead to the same error “go: command not found”.

            However, I did find a possibly temporary solution. Instead of saying “go install ….“, you list the full path rather than the alias itself. For example: “/usr/local/go/bin/go install …“. This solution might be limited as it will not work in situations where programs need a reference to GOPATH or PATH (w Go included).

            #4110

            Perhaps the shell isn’t bash? On many systems (Debian and perhaps Ubuntu too), /bin/sh is a symbolic link to dash, not bash.  On other systems, bash too will attempt to conform to POSIX standard if it is invoked as sh via a symbolic link.

            In either of those cases PATH might get picked up from ~/.profile, not ~/.bashrc.

          Viewing 5 posts - 1 through 5 (of 5 total)
          • You must be logged in to reply to this topic.