SSH parameter help on Ubuntu Server

1

I have a variable setup like this:

SSH_EXEC="ssh -X -o ControlPath=~/.ssh/master-$$ -o ControlPersist=60"

The parameter in question is the -X, because if I then call this command within my local script

$SSH_EXEC user@server "./server_script.sh $aFile"

which in a nutshell does the following:

if [ -e /path/"$1".name ] || [ -e /path/"$1" ]
then 
   do something
else
   error
   echo "/path/"$1".name"
   exit
fi  

Everything works! But if I replace -X with -t, my server_script fails to the else on the test. I'd prefer not use x11, but I'm not sure what the difference is that is causing it to fail in one instance, and pass in the other.

EDIT

So I just did more troubleshooting and decided to echo the value of /path/$1.name on the server and it is garbled junk. If my $aFile name happened to be hello.name the result of the echo shows .nameello and also rids the beginning of the path when I use -t in place of -X.

What could be causing the corruption of my variables?

hax0r_n_code

Posted 2013-06-13T14:26:53.717

Reputation: 215

You aren't using X11. In one case you enable X11 forwarding, in the other you force a pseudo-tty to be created. Also, your code "in a nutshell" doesn't contain enough (not even the echo) to tell what the problem might be. – Hasturkun – 2013-06-13T15:08:31.550

@Hasturkun I've modified my above example a little more. What I have "in a nutshell" is where my code fails. It's right at the beginning of a long server script. – hax0r_n_code – 2013-06-13T15:12:41.410

It's sort of a silly suggestion, but what happens if you pipe the output from your ssh command through xxd or similar? – Hasturkun – 2013-06-13T15:17:15.050

@Hasturkun not a silly question! I don't know what xxd is, could you elaborate? – hax0r_n_code – 2013-06-13T15:19:35.203

Hex dump. I'm guessing there are control characters in your output, eg. a ^H (backspace) would delete the characters before it in shell output. Would be visible in a hex dump. In this case, my psychic powers tell me it's a ^M (Carriage return) at the end of $aFile – Hasturkun – 2013-06-13T15:21:11.173

Do you think that doing a -o SendEnv $aFile would ensure the variable is properly transferred as an argument to the server script? – hax0r_n_code – 2013-06-13T15:24:05.847

let us continue this discussion in chat

– Hasturkun – 2013-06-13T15:25:16.107

Not sure why people are voting to close the thread since it clearly relates to programming? – hax0r_n_code – 2013-06-13T16:16:07.797

Answers

2

The variable $aFile probably has a trailing Carriage Return character, causing the terminal to return to the start of the line when encountered.

As an example, the following:

echo "/path/"hello^M".name"

outputs:

/.namehello

This sort of thing might happen due to a shell script with DOS line endings, causing a line like

aFile = "hello"

to be interpreted as

aFile = "hello"^M

If that's the case, you should be able to convert your script to use Unix line endings using the dos2unix utility.

Hasturkun

Posted 2013-06-13T14:26:53.717

Reputation: 326