Monday, November 26, 2007

Automatic Mount/Unmount Novell NetWare Shares in Linux

Purpose
  • Automatically mount Novell NetWare shares without prompting passwords when logging in.
  • Automatically unmount Novell NetWare shares without prompting passwords when logging out.

Configurations

  • "$HOME/.nwclient"
    • Create the file with permissions of "0600".
    • Add "Server/User Password" pair per each line as follows:
      NW_Server1/NW_UN1 PW1
      NW_Server2/NW_UN2 Password2

      where "NW_UN1/2" could be either just a NetWare username or
      a NetWare username appended by its context (e.g.,
      "joe.ee_dept.eng_school.great_univ").

  • "$HOME/.bash_profile"
    • Add "ncpmount" command as follows:
    • if [ ! -d /mount/point1/dir1_in_mounted_share ]; then
      # Check the above to prevent duplicate mount.
      ncpmount -S NW_Server1 -U NW_UN1 -u Linux_UN -V path/to/subdirectory1 -A NW_Server1_DNS_Name /mount/point1
      fi
      # We need "-m" below to allow multiple mounts from the same server.
      if [ ! -d /mount/point2/dir2_in_mounted_share ]; then
      ncpmount -S NW_Server2 -U NW_UN2 -u Linux_UN -V path/to/subdirectory2 -m -A NW_Server2_DNS_Name /mount/point2
      fi
      if [ ! -d /mount/point3/dir3_in_mounted_share ]; then
      ncpmount -S NW_Server2 -U NW_UN2 -u Linux_UN -V path/to/subdirectory3 -m -A NW_Server2_DNS_Name /mount/point3
      fi


  • "$HOME/.bash_logout"
    • Add "ncpumount" command as follows:
    •  if [ `w | grep pts | grep Linux_UN | wc -l` -eq 1 ]; then
      # The following will be executed only when this shell is the last login shell.

      if [ -d /mount/point1/dir1_in_mounted_share ]; then
      ncpumount /mount/point1
      fi
      if [ -d /mount/point2/dir2_in_mounted_share ]; then
      ncpumount /mount/point2
      fi
      if [ -d /mount/point3/dir3_in_mounted_share ]; then
      ncpumount /mount/point3
      fi
      fi