Are you trying to reach a URL on the same host you’re ssh-ing to? That would create some interesting effects.
Especially since it works the second time it could mean that the second time you’re actually on the host and ssh-ing to the host itself and then curling localhost.
Ah, I see. I guess they get different contexts or something? (Edit: I re-read your post and this does not make any sense :))
What if you chain the ssh command and the curl using &&?
Someone else suggested the env vars arent being expanded correctly inside the $(curl …), which could be the culprit … If a straight up URL works that would indicate that something like that is happening.
That said, I just tried setting an env var called URL=“” and curling it, and curl said exit code 2, no URL specified, so something else is going on here.
Exit code 7 means curl couldn’t connect to the host, so I would try just curling a URL you know is valid directly, not setting it as an env var, to see what happens then.
What exit code so you get from curl?
I had never heard of the (frankly horrible) band “Train” until recently.