Automount network samba drive on connection to network.

Question

I have two networks in my home. One for the internet and another specifically for file sharing and backup that isn’t connected to the internet. The one not connected to the internet has a nas that uses samba share. I was wondering if there is a way for the nas/ samba share drive to automount to my system when I connect its network?

 

Thanks

solved 0
PencilTester 3 months 5 Answers 274 views

Answers ( 5 )

  1. Hi PencilTester,

    Yes, there is a way. You have to use Linux Cron Jobs for that. Write a shell script that checks whether you’re connected to the network that has your NAS. If it is, then you mount the network share on your Linux machine. Once you’re done, configure the script to run every minute or every 5 to 10 minutes interval via Cron Job. That’s it.

    If you’re using a Linux desktop environment, then I think you don’t have to go through the troubles at all. You can simply mount your network share and bookmark the location on your file manager. Then, when you connect to the network and click on the bookmark, it will automatically be mounted and display the files on your Samba share.

     

    Thanks

    Shahriar Shovon

  2. Ok I will look into chron jobs. The end game of what I am trying to setup is this:

    Write a script that would have my system connect to the NAS network, mount the drive, then execute a backup using luckybackup/rsync, and then shoutdown the system once the backup is complete.

    So basically have my system do a backup on every shutdown.

     

     

  3. I see.

    In this case, you can also write a systemd service to do what you want. It will be simpler. Take a look at this link https://unix.stackexchange.com/questions/39226/how-to-run-a-script-with-systemd-right-before-shutdown

    Good luck. 🙂

     

    Best answer
  4. Thanks again i will try to see what i can do.

Leave an answer