Question: If i use 

```
ssh -Y username@hostname

```

and reach at another host and type x clock & it is working fine.But if i use it in script In online like

```
ssh -Y username@hostname x clock & ;

```

it gives me error as ksh: x clock: not found.

Please suggest.

Answer: 
First, I think that it should be `xclock` and not `x clock` (no space!). If you want to execute commands over SSH then ideally you would have something along the lines:

`ssh user@host 'ls -lrt'`
When you run the command on a single line, your remote shell will be in non-interactive mode. Because of that different scripts are executed in the remote shell, and because of that, your `PATH` setting is different.

One way to fix this is to find the script that sets the `PATH` of interactive shells, also find the script that is used by non-interactive shells, and adjust the latter to set the `PATH` similarly as the first.

Another solution that might be simpler is to use the full path in your command, follow these steps:

1. Login using `ssh`, as usual, and check the full path of the command you want to run. If the command is `xclock` then you can check its full path with `which xclock`, for example:

```
$ which xclock 
/usr/X11/bin/xclock

```
2. Logout, and run your one-line command, but using the full path like this:

```
ssh -Y username@hostname /usr/X11/bin/xclock

```