"text/plain": [

Exports

Quick and dirty script to simplify putting things into fstab.

  1. Copy-paste for directory creation.
  2. Copy-paste for shared drive mounting.
  3. Copy-paste for fstab (for permanent mounts).
In [1]:
HOST="freenas.lan"
server=HOST
import subprocess
cmd_array=["showmount","-e",HOST]
result = subprocess.check_output(cmd_array)
print(result.decode())
Exports list on freenas.lan:
/mnt/tank/ftp                      Everyone
/mnt/tank/TV                       Everyone
/mnt/tank/Poudriere                Everyone
/mnt/tank/PictureUploads           Everyone
/mnt/tank/NVR                      Everyone
/mnt/tank/KidsTV                   Everyone
/mnt/tank/Incoming                 Everyone
/mnt/tank/DVR                      Everyone
/mnt/keg/homes/jafrey              Everyone
/mnt/keg/homes                     Everyone
/mnt/keg/Videos                    Everyone
/mnt/keg/Python                    Everyone
/mnt/keg/Pictures                  Everyone
/mnt/keg/Embedded                  Everyone
/mnt/keg/Caterpillar               Everyone

Get Export Paths

In [2]:
exports=result.decode().split("\n")[1:]
exports[0].split(" ")[0]
paths=list()
for export in exports:
    path = export.split(" ")[0]
    if len(path)>0:
        paths.append(path)
paths
Out[2]:
['/mnt/tank/ftp',
 '/mnt/tank/TV',
 '/mnt/tank/Poudriere',
 '/mnt/tank/PictureUploads',
 '/mnt/tank/NVR',
 '/mnt/tank/KidsTV',
 '/mnt/tank/Incoming',
 '/mnt/tank/DVR',
 '/mnt/keg/homes/jafrey',
 '/mnt/keg/homes',
 '/mnt/keg/Videos',
 '/mnt/keg/Python',
 '/mnt/keg/Pictures',
 '/mnt/keg/Embedded',
 '/mnt/keg/Caterpillar']

Make Directories

In [3]:
for path in paths:
    print("mkdir -p {path}".format(path=path))
mkdir -p /mnt/tank/ftp
mkdir -p /mnt/tank/TV
mkdir -p /mnt/tank/Poudriere
mkdir -p /mnt/tank/PictureUploads
mkdir -p /mnt/tank/NVR
mkdir -p /mnt/tank/KidsTV
mkdir -p /mnt/tank/Incoming
mkdir -p /mnt/tank/DVR
mkdir -p /mnt/keg/homes/jafrey
mkdir -p /mnt/keg/homes
mkdir -p /mnt/keg/Videos
mkdir -p /mnt/keg/Python
mkdir -p /mnt/keg/Pictures
mkdir -p /mnt/keg/Embedded
mkdir -p /mnt/keg/Caterpillar

Mount Shares

In [4]:
for path in paths:
    print("mount.nfs {server}:{path} {path}".format(server=server,
                                   path=path))
mount.nfs freenas.lan:/mnt/tank/ftp /mnt/tank/ftp
mount.nfs freenas.lan:/mnt/tank/TV /mnt/tank/TV
mount.nfs freenas.lan:/mnt/tank/Poudriere /mnt/tank/Poudriere
mount.nfs freenas.lan:/mnt/tank/PictureUploads /mnt/tank/PictureUploads
mount.nfs freenas.lan:/mnt/tank/NVR /mnt/tank/NVR
mount.nfs freenas.lan:/mnt/tank/KidsTV /mnt/tank/KidsTV
mount.nfs freenas.lan:/mnt/tank/Incoming /mnt/tank/Incoming
mount.nfs freenas.lan:/mnt/tank/DVR /mnt/tank/DVR
mount.nfs freenas.lan:/mnt/keg/homes/jafrey /mnt/keg/homes/jafrey
mount.nfs freenas.lan:/mnt/keg/homes /mnt/keg/homes
mount.nfs freenas.lan:/mnt/keg/Videos /mnt/keg/Videos
mount.nfs freenas.lan:/mnt/keg/Python /mnt/keg/Python
mount.nfs freenas.lan:/mnt/keg/Pictures /mnt/keg/Pictures
mount.nfs freenas.lan:/mnt/keg/Embedded /mnt/keg/Embedded
mount.nfs freenas.lan:/mnt/keg/Caterpillar /mnt/keg/Caterpillar

Create /etc/fstab lines

In [5]:
server="freenas.lan"
mount_type="nfs"
mount_options="rw,noatime"
print("# NFS Mounts from {}".format(HOST))
for path in paths:
    print("{server}:{path} {path} {mount_type} {mount_options} 0 0".format(server=server,
                                                                   path=path,
                                                                   mount_type=mount_type,
                                                                   mount_options=mount_options))
# NFS Mounts from freenas.lan
freenas.lan:/mnt/tank/ftp /mnt/tank/ftp nfs rw,noatime 0 0
freenas.lan:/mnt/tank/TV /mnt/tank/TV nfs rw,noatime 0 0
freenas.lan:/mnt/tank/Poudriere /mnt/tank/Poudriere nfs rw,noatime 0 0
freenas.lan:/mnt/tank/PictureUploads /mnt/tank/PictureUploads nfs rw,noatime 0 0
freenas.lan:/mnt/tank/NVR /mnt/tank/NVR nfs rw,noatime 0 0
freenas.lan:/mnt/tank/KidsTV /mnt/tank/KidsTV nfs rw,noatime 0 0
freenas.lan:/mnt/tank/Incoming /mnt/tank/Incoming nfs rw,noatime 0 0
freenas.lan:/mnt/tank/DVR /mnt/tank/DVR nfs rw,noatime 0 0
freenas.lan:/mnt/keg/homes/jafrey /mnt/keg/homes/jafrey nfs rw,noatime 0 0
freenas.lan:/mnt/keg/homes /mnt/keg/homes nfs rw,noatime 0 0
freenas.lan:/mnt/keg/Videos /mnt/keg/Videos nfs rw,noatime 0 0
freenas.lan:/mnt/keg/Python /mnt/keg/Python nfs rw,noatime 0 0
freenas.lan:/mnt/keg/Pictures /mnt/keg/Pictures nfs rw,noatime 0 0
freenas.lan:/mnt/keg/Embedded /mnt/keg/Embedded nfs rw,noatime 0 0
freenas.lan:/mnt/keg/Caterpillar /mnt/keg/Caterpillar nfs rw,noatime 0 0
In [ ]:
 
In [ ]: