What is the code to make a script run on startup that binds the home folders with other folders depending on if a drive is present?
Because most of my files are kept in separate drives and places than /home/John/Folder, I use Terminal code to bind the Home folders for different places. For example, I bind the /Documents folder with /Dropbox/Documents so it's constantly backed up. I've found out how to do this through the terminal, and read somewhere that you can put code in the /etc/rc.local script and that that script (rc.local) runs on start up. I've put the code into that script, but I'm not sure how to get that to run on startup. Right now I have to wait till the computer has started up, then run the code in the terminal. The full code in that script I've set is below.
sudo mount -o bind /media/Storage/Music ~/Music && sudo mount -o bind /media/storage/downloads ~/Downloads && sudo mount -o bind /media/2TB/Videos ~/Videos && sudo mount -o bind /home/john/dropbox/documents ~/Documents && sudo mount -o bind /home/john/dropbox/Photos ~/Pictures && exit 0
The exit 0 is needed for the script to run, according to a comment in the script.
Since this on a laptop and I keep my video files on an external drive, is there anyway to add a simple "If is present, also bind ~/Videos to /media//Videos," and if it's not, skip over it? Or put that code at the end so it doesn't affect the above execution?
There are multiple issues with your script:
The folllowing script will do what you have requested:
In a BASH script...
You can also stop using the && this way. (If you have
command1 && command2
, command2 is executed if and only if command1 exited with exit code 0 (success).) And you have some local, some network. The network portion might belong in scripts placed in /etc/network/if-up.d and /etc/network/if-down.d. The local portion might belong in /etc/rc.local - to stop using sudo command.