3

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?

  • 1
    Use the soft option rather than hard when mounting the filesystem. Or make local copies of the relevant scrips. – Satō Katsura Feb 19 '17 at 13:32
1

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.

  • Well, this makes lots of sense. Sorry for my delay in accepting the answer! – Aaron Brick Jan 23 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.