Search code examples
bashnetwork-programmingmount

Using a bash script on a Mac to connect to network shares?


I'm using a Mac at work and would like some network shares mounting when i start the computer. Can i use a bash script (or similar) to connect and mount these shares? The shares are from both Windows and Mac servers and we usually connect using IP addresses.


Solution

  • You could check out mount_smbfs, assuming that your network shares are smbfs/cifs.

    mount_smbfs [-N] [-o options] [-d mode] [-f mode] [-h] //[domain;][user[:password]@]server[/share] path
    

    I'm not intimately familiar with the OSX startup process, but it's possible you can create your shell-script as a program/folder in /Library/StartupItems or /System/Library/StartupItems

    As mentioned on osxbook.com

    /etc/rc finally launches /sbin/SystemStarter to handle startup items from locations such as /System/Library/StartupItems and /Library/StartupItems. A StartupItem is a program, usually a shell script, whose name matches the folder name. The folder contains a property list file containing key-value pairs such as Description, Provides, Requires, OrderPreference, start/stop messages etc. You can run SystemStarter -n -D as root to have the program print debugging and dependency information (without actually running anything).