0

I am trying to get the contents of a symlink remotely, but I am having a hard time understanding why is not working.

I tried following the example on this post. but is not working for me. This is what I am trying to do.

$PATH_LINK=~/some/directory/to/link
SYMB_LINK=`ssh files@files_server.com 'readlink $PATH_LINK'`

but I get $readlink: missing operand

I can get it to work if I write the path in the command.

SYMB_LINK=`ssh files@files.files_server.com 'readlink path/to/file'`

I tried running it without the -f but still gives me the same problem.

Community
  • 1
  • 1
  • use dbl-quotes around `"readlink -f $PATH_LINK"`. If you /path/to/link has spaces, then you'll have to use a combination of single and dbl-quotes to ensure that /path/with spaces/to/link is passed as 1 argument to readlink. Good luck. – shellter Aug 17 '16 at 03:43
  • Thank you shelter! it worked! – marco-andarcia Aug 17 '16 at 03:51

2 Answers2

1

First of all, don't use ~ because that will probably be expanded by your shell using the user settings of the user on your local machine rather than the remote machine.

Secondly, you should not use the $ character on the left-hand side when assigning to a shell variable.

Taking all this advice and combining it together, we get:

LINK_PATH=/home/david/link
LINK_TARGET=$(ssh example.com "readlink $LINK_PATH")
David Grayson
  • 84,103
  • 24
  • 152
  • 189
0

@shelter came with the solution to my problem. I was using the wrong quotes.

this is the correct format:

SYMB_LINK=`ssh files@files.files_server.com "readlink path/to/file"`