marco-andarcia marco-andarcia - 1 year ago 138
Linux Question

Read Symlink remotely in Linux

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.

SYMB_LINK=`ssh '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 'readlink path/to/file'`

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

Answer Source

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_TARGET=$(ssh "readlink $LINK_PATH")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download