Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/usr/bin/env: ln: Too many levels of symbolic links

This problem is killing me and I feel like I've tried everything.

First off, the problem started happening when upgrading to Capistrano 3. Capistrano now utilizes /usr/bin/env before every command when deploying, to make sure the environment setup is correct.

When Capistrano goes to create symlinks to the necessary shared directory and respective files, it attempts commands like:

/usr/bin/env ln -s /full/path /different/full/path

...and then it errors out:

/usr/bin/env: ln: Too many levels of symbolic links

I realize it's not Capistrano's fault, so I began troubleshooting by ssh'ing to my server and trying the same command, and I receive the same error (which at least is good for consistency). I then try the same command without /usr/bin/env:

ln -s /full/path /different/full/path

And it works!!!! Maybe you can see the real solution that I can't?

here is the output of just the /usr/bin/env command:

rvm_bin_path=/home/deployer/.rvm/bin
GEM_HOME=/home/deployer/.rvm/gems/ruby-1.9.3-p392
TERM=xterm-256color
SHELL=/bin/bash
IRBRC=/home/deployer/.rvm/rubies/ruby-1.9.3-p392/.irbrc
SSH_CLIENT=...
OLDPWD=/home/deployer/Sites/example.com
MY_RUBY_HOME=/home/deployer/.rvm/rubies/ruby-1.9.3-p392
SSH_TTY=/dev/pts/0
USER=deployer
LS_COLORS= .....
_system_type=Linux
rvm_path=/home/deployer/.rvm
SSH_AUTH_SOCK=....
rvm_prefix=/home/deployer
MAIL=/var/mail/deployer
PATH=/home/deployer/.rvm/gems/ruby-1.9.3-p392/bin:/home/deployer/.rvm/gems/ruby-1.9.3-p392@global/bin:/home/deployer/.rvm/rubies/ruby-1.9.3-p392/bin:/home/deployer/.rvm/bin:/opt/rubyee/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/deployer/.rvm/bin
PWD=/home/deployer/Sites
LANG=en_US.UTF-8
_system_arch=i386
_system_version=12.04
rvm_version=1.26.4 (latest)
SHLVL=1
HOME=/home/deployer
LOGNAME=deployer
GEM_PATH=/home/deployer/.rvm/gems/ruby-1.9.3-p392:/home/deployer/.rvm/gems/ruby-1.9.3-p392@global
SSH_CONNECTION=....
LESSOPEN=| /usr/bin/lesspipe %s
LESSCLOSE=/usr/bin/lesspipe %s %s
RUBY_VERSION=ruby-1.9.3-p392
_system_name=Ubuntu
_=/usr/bin/env

I have also tried commands like the following, to find potential symlink loops:

find . -maxdepth 20 -type l -exec ls -ld {} +

But is not producing correct results:

lrwxrwxrwx 1 deployer deployer ...
like image 793
mkralla11 Avatar asked Dec 15 '14 18:12

mkralla11


People also ask

How do you resolve too many levels of symbolic links?

There are two ways to solve the “Too many levels of symbolic links” error. We can pass the source parameter as either an absolute or relative path.

What does too many levels of symbolic links mean?

The "too many levels of symbolic links" message means that 40 symlinks have been traversed in attempting to resolve a path to an object. It nearly always happens because you have a symlink that directly or indirectly points to itself.

How do I remove all symlinks?

To remove a symbolic link, use either the rm or unlink command followed by the name of the symlink as an argument. When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.

How do I remove a symbolic link Mac?

Another method to delete the symlink service from the contextual menu is to open System Preferences, select Extensions, click Finder, uncheck your quick symlink option in the main panel, right-click it, and then select Move to Trash.


1 Answers

You might not being using the same ln utility.

When invoking it directly from the interactive shell, ln might be overridden e.g. by an alias or by some shell function ln() {...;}.

This does not happen when /usr/bin/env tries to do that (AFAIK it looks for ln in PATH). I suspect that the ln it finds has issues, so you are getting this error.

This is an example scenario that might be similar to your case:

# start from an empty directory
$ ls -l
total 0
# create a problematic `ln` in the current directory
$ ln -s ln ln
$ ls -l
total 0
lrwxrwxrwx 1 me me 2 Jan  7 20:28 ln -> ln
# have an alias for the "real" ln
$ alias ln=/bin/ln
# mess up PATH
$ PATH="$PWD"

Now let's try the two alternatives, /usr/bin/env goes first:

$ /usr/bin/env ln -s /some/path /tmp/path
/usr/bin/env: ln: Too many levels of symbolic links

Then plain ln (remember that we aliased it):

$ ln -s /some/path /tmp/path
$ echo $?
0
$ /bin/ls -l /tmp/path
lrwxrwxrwx 1 me me 10 Jan  7 20:31 /tmp/path -> /some/path

So my suggestion is: look at issues with ln, e.g. by finding all different alternatives that might be visible. In bash you might run this:

$ type -a ln
like image 78
polettix Avatar answered Sep 29 '22 09:09

polettix