Running a script at startup

Eric4526

New Member
Joined
May 23, 2022
Messages
1
Reaction score
0
Credits
15
I have a script to mount 2 network drives that work perfectly from the terminal using "sudo sh MntPD". This is the content of the MntPD file:

#!/bin/bash
sudo mount.cifs //10.0.0.2/drobo5n2/VideoMedia /media/plexdata -o vers=2.0,username=USERNAME,password=PASSWORD,noperm
sudo mount.cifs //192.168.12.102/drobo5n2 /media/Drobo5n2 -o vers=2.0,username=USERNAME,password=PASSWORD,noperm
exit 0

I have tried using crontab, systemd and rc.local to have this script run automatically at startup with no success. I have modified startup so that no password is required for the sudo command. How can I get this script to run automatically?
 


Instead of putting sudo in each command in the script..
have you tried simply running the entire script with sudo. Or perhaps in root's crontab.
 
Why not just put that in /etc/fstab without the mount and the sudo commands?
 
Last edited:
Are the drives auto mounted on start up or not, if so why not.
If you can find the drives UUID using Gparted or partitionmanager then
put a line for each drive into your /etc/fstab file.
Exchange your drive UUID and mount path, the below mounts the
drive HDDL2 on /media , note I have ntfs as the file type, change that to
your file type. the 1000 gives access to owner root with full control.

Code:
UUID=3FAC12281A1EAB69  /media/HDDL2  ntfs uid=1000,gid=1000  0  2
If there is a posabillity you may forget to plug the drive in like with a USB
connected drive, you should add the nofail flag in the line too, otherwise boot
will take a long time and in a lot of cases not boot at all.
nofail tells the system its not required, and boot will proceed without fail.
Here is an example below.
Code:
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
the 4th column is where you change your mount options. In your case, change defaults to defaults,nofail

UUID=123ec4fd-54e2-4590-8a4b-da43630efd72 /media/Data1 ext4 defaults,nofail 0

Code:
UUID=3FAC12281A1EAB69  /media/HDDL2  ntfs defaults,nofail uid=1000,gid=1000  0  2
 
Last edited by a moderator:


Top