I've run into a nuance of ssh that I'd like to solve. Here's the setup:
I'm running a GUI program that launches commands via the "system" function. One such command is 'ssh -X account@remote "./startup"'. Inside the 'startup' script, I set the display variable to localhost:10.0. The desired result is that the X window of the remote program shows up locally. It works when in a terminal:
1. ssh -X account@remote <enter>
./startup
Setting DISPLAY explictly is redundant here because the .bashrc is run.
2. ssh -X account@remote "./startup"
Setting DISPLAY explicitly in script needed because it doesn't get set.
In the program, the call 'system("ssh -X account@remote \"./startup\"")' yields a 'Can't open display: localhost:10.0'. Here's the kicker though, it works if ANOTHER terminal is already sshed into that machine. This probably has something to do with the .Xauthority file.
My question is how can I make this work WITHOUT having to ssh into the machine from another terminal? Any other approaches to this are welcome.
Test script on remote machine (replace gcalctool with any X windows program)
Code:
#! /bin/bash
export DISPLAY=localhost:10.0
gcalctool
Program to execute command:
Code:
#include <stdlib.h>
int main(int argc,char *argv[])
{
system("ssh -X account@remote \"./startup\"");
return 0;
}
BTW, using mostly CentOS 5, and one machine is Fedora Core 2 (I know, but it's got special hardware)