0

I am trying to reduce typing by writing a script executing several ssh commands. While it is no problem to simply open an editor for example, I can't open an editor with a specific file:

this works:

editFile="ssh -X -t $username@$serverIP 'nano'"
$editFile

this doesn't:

editFile="ssh -X -t $username@$serverIP 'nano ~/test'"
$editFile

I also cannot connect to a screen like so, while simply starting screen works fine:

viewScreen="ssh -X -t $username@$serverIP 'screen -r screen1'
$viewScreen

If I add a -v flag, after the connection is established I get this error:

debug1: Sending command: 'nano /home/herb/.Scripts/test.txt'
bash: nano ~/test: No such file or directory

debug1: Sending command: 'screen -r screen1'
bash: screen -r screen1: command not found

Both commands work without a problem if typed in a terminal, so there must be some kind of magic I'm missing here!

herbert
  • 9
  • 2

1 Answers1

3

One problem is that you are using single quotes for the "command" argument. Without them, it should work (or at least give you a different error).

You should also use the "alias" command instead of assigning the commands to variables:

alias viewScreen="ssh -X -t $username@$serverIP screen -r screen1"
viewScreen

be aware that this evaluates variables when defining the alias. $username and $serverIP should therefore be defined before.

niko
  • 1,816
  • 13
  • 13
  • replacing the single quotes with double quotes gave the same error... – herbert Jun 17 '12 at 14:21
  • 1
    sorry accidentally sent off the comment prematurely... As an experiment I used it like you put it, without any quotes and it worked! except it only works when I use a variable, the alias method gives me a command not found! I was under the impression the single/double quotes around the command part are required.. apparantly they were the only reason the script was failing. Could you give me another hint why I should use alias and how? – herbert Jun 17 '12 at 14:28