Get Remote Variable

So here is my delemia,
I am working on a fork of https://github.com/cdr/sshcode, the goal is to make window supported https://github.com/Merith-TK/sshcode/tree/msys-support

the problem is that when windows sends a path, i have narrowed it down to the issue being that windows sends the path string as a litteral path,
so the path ~/whatever is sent as '~'/whatever which is technically a “valid” path

I want to implement into the code a check

if runtime.GOOS = windows {
    // get remote $HOME variable    
    //replace ~ with $HOME in all strings
}
2 Likes

There is a runtime package and you can check if is running in Windows or not. Something like

package main

import (
    "fmt"
    "runtime"
)

func main() {

    if runtime.GOOS == "windows" {
        fmt.Println("You are running on Windows")
    } else {
        fmt.Println("You are running on an OS other than Windows")
    }
}
2 Likes

Yeah i can understand that part, that is what i was gonna use. But the issue is getting $HOME from the linux server.
(that is the exact code needed,)

I need help pulling $HOME from the server (no code can be ran on the server except via SSH)

2 Likes

Ok…
Maybe using os.Environ() could do the trick…

2 Likes

Checking the docs, there are other methods like:

  • os.LookupEnv
  • os.Getenv
2 Likes

Do you have any idea how i can execute this on the remote machine?

this looks like it might beable to do what i want

2 Likes

It seems to me you want to create a kind of server of remote command. Say In a client machine i would send a command to that server and this executes in the remote machine. If so, an easiest way to do that is create a http server to receive comands using a url…
Tell me if I am fully understand what you want to do…

2 Likes

Does (*user.User).HomeDir have what you want? https://golang.org/pkg/os/user/

2 Likes

@Yamil_Bracho That would kinda go against the program, but it would be FEASABLE atleast, as sshcode already pulls a binary to exec and then sshproxy back,

@skillian the problem with that, is as far as i know on how to use that, i can only get the HomeDir of the client, not the server

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.