Override path to binary for particular user

12,878

Solution 1

If the binary is in /usr/bin/binary and the script invokes the binary without specifying the full path, but instead relies on /usr/bin being in PATH then you can simply add the location of the new binary to the beginning of the user's PATH. Put something like this in their ~/.bashrc:

PATH=/mount/new_version:$PATH

For security reasons, scripts often specify the full path to binaries to prevent this kind of thing.

Solution 2

If you have access to the binary you can backup it and create a symbolic link.

mv /urs/bin/binary /urs/bin/binary.bkp
ln -s /mount/new_version/binary /urs/bin/binary

[EDIT]

Sorry, didn't saw the change must be done for one user only.

You can create a function to be called instead of the binary.

Depending on how you execute the binary (full path or just name) you must create a suitable function, like:

# Full path
function /urs/bin/binary () { command /mount/new_version/binary "$@"; }
export -f /urs/bin/binary
# Name
function binary () { command /mount/new_version/binary "$@"; }
export -f binary

If the binary don't accept/need arguments, remove the "$@".

To automatize the function creation, put the function lines in the .profile file in the user home directory.

Solution 3

alias commandname=/mount/new_version/binary

in the .bashrc above the path statement/export or in the profile will accomplish easy enough.

Share:
12,878

Related videos on Youtube

Viktor Stolbin
Author by

Viktor Stolbin

I'm a senior java developer with 7 years of strong enterprise experience and 1 year in game development. Currently I'm working in high-load distributed over the world project. Feel free to contact me.

Updated on September 18, 2022

Comments

  • Viktor Stolbin
    Viktor Stolbin over 1 year

    My question seems to be trivial but I didn't manage to find anything helpful in internet. I have a binary in

    /urs/bin/binary
    

    but it is outdated and newer version is available on some mount for example

    /mount/new_version/binary
    

    An there's a bash script that invokes this binary in a form like

    binary -doSomething
    

    I need this script to invoke new version of binary instead of old one but I'm not permissioned to change this script. Is is a way to somehow override path to it but only for my user? Any help would be appreciated.

    • FooBee
      FooBee over 10 years
      If you are not allowed to do it, talk to your admin.
  • Viktor Stolbin
    Viktor Stolbin over 10 years
    This will affect all users. It's not acceptable.