Advertisement
Guest User

automounter samba script

a guest
Mar 28th, 2012
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #!/bin/bash
  2. # $Id: auto.smb,v 1.3 2005/04/05 13:02:09 raven Exp $
  3. # This file must be executable to work! chmod 755!
  4.  
  5. key="$1"
  6. credfile="/etc/auto.smb.$key"
  7.  
  8. opts="-fstype=cifs,uid=1000,gid=1000"
  9. smbclientopts=""
  10.  
  11. for P in /bin /sbin /usr/bin /usr/sbin
  12. do
  13. if [ -x $P/smbclient ]
  14. then
  15. SMBCLIENT=$P/smbclient
  16. break
  17. fi
  18. done
  19.  
  20. [ -x $SMBCLIENT ] || exit 1
  21.  
  22. if [ -e "$credfile" ]
  23. then
  24. opts=$opts",credentials=$credfile"
  25. smbclientopts="-A "$credfile
  26. else
  27. smbclientopts="-N"
  28. fi
  29.  
  30. $SMBCLIENT $smbclientopts -gNL $key 2>/dev/null| awk -v key="$key" -v opts="$opts" -F'|' -- '
  31. BEGIN { ORS=""; first=1 }
  32. /Disk/ {
  33. if (first)
  34. print opts; first=0
  35. dir = $2
  36. loc = $2
  37. # Enclose mount dir and location in quotes
  38. # Double quote "$" in location as it is special
  39. gsub(/\$$/, "\\$", loc);
  40. print " \\\n\t \"/" dir "\"", "\"://" key "/" loc "\""
  41. }
  42. END { if (!first) print "\n"; else exit 1 }
  43. '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement