Get to know Linux: Bash scripting basics

Status
Not open for further replies.

Osiris

Golden Master
Messages
36,817
Location
Kentucky
Source Get to know Linux: Bash scripting basics

After using Linux for a while you will eventually find yourself needing to create a bash script. And just what is a bash script? A bash script is a script that is run through the bash shell. Usually a bash script is a user-generated script that serves a specific purpose and combines numerous commands into one convenient script.
I am a big fan of bash scripting. I use them frequently to create backup scripts, scripts that are used via cron, and much more. But before I could write even a simple bash script, I had to understand the basics. And that's what you will learn here - the very basics of bash scripting. This will be a foundation you can build upon so that your bash scripts can get more and more complex.
 
Just to share personal experience: I have a spare hard drive in my computer of ample size compared to my primary. I created a script as follows:

#!/bin/bash
rsync -a --progress --delete /home/jason/ /media/storage/localbackup/

I named it "backup" and ran sudo chmod +x /usr/local/bin/backup (where the file is stored).

That command made it executable.

Then I edited crontab to run "backup" as user "jason" (who also owns the file) @ 4 AM and 4 PM.

So when my hard drive dies, like my lovely brand new Seagate did last month, data-wise : I'm covered. :)
 
Status
Not open for further replies.
Back
Top Bottom