4

Some of the scripts I run are located on a CIFS filesystem hosted on another machine. I mount that filesystem over the network and add the remote location of the scripts to my $PATH. This works great in normal conditions. However, if the remote machine goes offline or hangs up for some reason, it can make using the command line downright horrible as every tab completion or command entry blocks looking for programs on the remote host. Opening a new terminal window also hangs as the shell is starting.

What's a good way to ameliorate this problem while maintaining the utility of the $PATH lookup mechanism?

Aaron Brick
  • 401
  • 2
  • 10

1 Answers1

2

A workaround that might work for you is to create a bunch of wrapper scripts in a local directory, and put that in your search path instead of the remote directory. This isn't a panacea: you need to update the wrappers each time the content of the remote directory changes. But this way there's no access to the remote file unless you're executing the program.

You need a symbolic link and not a wrapper script because completion will sometimes check whether the files are executable, which means a stat call on the files. But all the wrappers can be symbolic links to a single executable file.

  • Once and for all, create a local directory ~/remote-scripts and an executable file ~/remote-scripts/.remote-wrapper containing

    #!/bin/sh
    exec "/remote/path/bin/${0##*/}" "$@"
    
  • To update ~/remote-scripts, run this snippet:

    find ~/remote-scripts -type l -exec rm {} +
    for x in /remote/path/bin/*; do ln -s .remote-wrapper ~/remote-scripts/"${x##*/}"; done
    
  • Put ~/remote-scripts in your PATH.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175