Using Variables in a Bash Backup Script

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

Bash scripting is an invaluable skill for a Linux system administrator. From writing quick scripts that automate simple tasks to writing complex scripts than can automatically deploy entirely new servers, scripting skills are integral to being a good SysAdmin. In this lab, we’ll integrate bash variables into an existing backup script.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Modify the Backup Script to Use Variables That Would Allow Other Users to Successfully Run the Script

Ensure that any references to "cloud_user" are replaced by a variable that will reference the username of the user running the script.

Add a Parameter to Determine the Name of the Log File

Add a variable for the log file that will be populated by a parameter passed on the command line.

Run the Script in Each User’s Home Directory to Ensure That It Works

Mark the script as executable and run it, then verify that all files are backed up to the required directory.

Additional Resources

You work for Universe Incorporated. One of your users — cloud_user — has an already existing backup script. There's been a request from two other users — adent and zbee — to have the same script made available. Modify /home/cloud_user/backup.sh to include using bash variables for the user directories and user names. Feel free to include variables for anything else you'd like.

Once complete, copy the script to the other user directories, and ensure it runs and successfully backs up the required files.

If you get stuck, feel free to check out the solution video or the detailed instructions under each objective. Good luck!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!