Mount NFS Share On NFS Client via bash script.

I need a help of good people with effective bash script to mount nfs shared,
By the way I did the searches, since i haven't found that someone wrote a script like this in the past, I'm sure it will serve more people.

The scenario as follow:
An NFS Client with Daily CRON , running bash script that:
Reading the output of:

showmount -e server01.example.com

And if certain mount does not exist In /etc/fstab.
It will insert the mount to /etc/fstab with following nfs attribute and options,
With creation of relevant "/nfs/x" shares, under the "/nas" directory on client.

server01.example.com:/nfs/test /nas/test nfs tcp,hard,intr,noatime 0 0
server01.example.com:/nfs/data /nas/data nfs tcp,hard,intr,noatime 0 0
server01.example.com:/nfs/logs /nas/logs nfs tcp,hard,intr,noatime 0 0

Thanks all.

Are you aware of the /net/server01.example.com/ feature in automounter?
It is activated by /net -hosts in /etc/auto.master and starting the autofs service.

Hi, Made.
I'm familiar with "/net" of the autofs terminology,
but in my case i will need to apply it via bash script.
I came across a several scripts that mount nfs shares on client ,But what is common to all, is that you required to specify the shared/exports.

And in my case the path = x
server01.example.com:/nfs/x

i.e :
Situation where someone added a new line to NFS Server /etc/exports,
And Client will handle on the mount through bash script that:

  1. Read showmount -e
    2.Verify that /nfs/x already exist in /nas under fstab
    if not:
  2. Create folder
  3. Add it to fstab with under "/nas/x" with "nfs tcp,hard,intr,noatime 0 0"
  4. mount share.

And what speaks against a symbolic link /nas -> /net/server01.example.com ? Then you don't need the bash script.
Try with /nas2 first so you can compare with your existing /nas

May I question the point of having a daily job to update /etc/fstab ? Even if shares were added frequently (daily), you wouldn't see them but the next day. And, what about removed shares?

If the clients are continuously up and running, create a script that actively distributes the new (or removed!) share info from the server to all the clients. If they aren't, a daily cron doesn't help anyway (but mayhap a boot script to fetch that info and update the local tables).