amingilani amingilani - 1 year ago 54
Linux Question

How do I link a ruby script to /usr/local/bin so that whenever can find it

I made a script, and I need

to run it via cron every

Linking it with
ln -s scruffy.rb /usr/local/bin
goes fine but then this happens:

gilani@raspberrypi:~ $ /usr/local/bin/scruffy.rb
-bash: /usr/local/bin/scruffy.rb: Too many levels of symbolic links

Where and how do I setup a symbolic link so that cron can run my script?

Answer Source

Try this:

ln -s /absolute/path/to/scruffy.rb /usr/local/bin
      ^^^^^^^^^^^^^^^^^^ adjust this path

Your original command generates a symlink called /usr/local/bin/scruffy.rb with a target set to scruffy.rb. The problem is that relative paths in symlink targets are interpreted to be relative to the directory containing the symlink, not relative to path where you run the ln command from. So now /usr/local/bin/scruffy.rb is a symlink to itself, because the relative path scruffy.rb interpreted to be relative to /usr/local/bin gives you back the symlink itself. So you've a link pointing to itself, which creates an infinite loop.

Edit: If you don't want to type the complete absolute path to scruffy.rb and you execute the ln from the directory that it contains it, you can simply do:

ln -s "$PWD/scruffy.rb" /usr/local/bin

as mudasobwa pointed out.