bash checking directory existence hanging when NFS mount goes down

≯℡__Kan透↙ 提交于 2019-12-23 22:29:20

问题


I have a .bash_profile script that sets up some aliases for me based on directory existence:

if [ -d  /home/user/games ] ; then
  alias cdgames='cd /home/user/games'
fi

One of these directory is on an NFS mount - if the filer becomes unresponsive su - user will hang on this line in .bash_profile.

Is there any way to check existence of a directory in bash without causing a hang if the directory is mounted to an unresponsive filer?


回答1:


As the folder should appear as a mount device in /etc/mtab you can try something like this

if grep -q '/home/user/games' /etc/mtab ; then 
    alias cdgames='cd /home/user/games'
fi

This approach is a bit rude but it works for most of the situations.



来源:https://stackoverflow.com/questions/9159839/bash-checking-directory-existence-hanging-when-nfs-mount-goes-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!