Nugget Challenges and Case Studies

In this section of the web we present you with practice projects.  Each challenge will have a stated objective, suggested components to work with, and a posted answer.  Work through all the challenges to reinforce the concepts for each respective video series.  Have fun.

CompTIA Linux+ Challenges
Nugget Challenge #1:File Sharing and Permissions [answer]
Nugget Challenge #2: Scripting a Backup [answer]

Nugget Challenge #1: File Sharing and Permissions

The point of this exercise is to make it so that three users can share files in a directory named /misc/amigos_share and anyone outside of those three users can't even list the files in the directory. How can you accomplish this? What special reminders or instructions should you give to the three users so that everything works smoothly?

The Answer:

The best way to do this is to create a group that has read, write and execute permissions on the /misc/amigos_share directory. Other users (except for root) should have no permissions on this directory. Then add the three users to the group and they should have full access to the /misc/amigos_share directory. 

Here's how I did it, there's certainly other ways to do it. As long as each of the three users has full access to the directory and no other normal user accounts can list files in that directory you've done it correctly. 

A) As the root user create a group. I'll call mine amigos and do it like this:

groupadd amigos

B) Set the three usernames to be part of the amigos group. One way to do this is:

usermod -G amigos alice
usermod -G amigos bob
usermod -G amigos candy

C) Create the directory for them to use under /misc. One way to do this is:

cd /misc
mkdir amigos_share

D) Now change permissions on the /misc/amigos_share directory so that the group (but not others) can access the directory.
One way to do this is:

chmod 770 amigos_share

E) Now Alice, Bob, and Candy can enter the /misc/amigos_share directory and create and edit files in that directory. 

Be sure to remind the three amigos that when they edit files in that directory the group ownership we be changed to their default group (in Red Hat Linux that would be their user private group, in other versions of Linux it will probably be something like "users"). Tell them that typing "newgrp amigos" will make amigos their default group for this login session and so any files they change after typing that command will have group ownership of amigos. 

back to top

Nugget Challenge #2: Scripting a Backup

The point of this exercise is to create a shell script that performs an incremental backup of your system. Let's say that it backs up the /home and /etc directories and stores the backup in a file called backup-date.tar (where date is some representation of the current date) so that you can distinguish between different backups. 

Also, make it so that the shell script runs every day at 2:30 a.m. except the first day of the month (which is when we'll assume full backups are done ... we'll just ignore differential backups for this example). 

The Answer:

A simple command that performs an incremental back up of the /home and /etc directories would look something like this:

tar cvpf /var/backup-date.tar --newer 10Jun2002 /home /etc

Putting that into a shell script verbatim would be easy. But we can't put it in verbatim because we have to make it so the script puts the date in there by itself. Below is the shell script that I wrote (sans comments) and I'll explain it as I go. (NOTE: bold denotes the text of the script)

#!/bin/bash

month=`date | cut -f2 -d " "`


The above code extracts the month (such as May, Jul, Sep) from the date command, month is the second field which is why I use -f2, and I specify to use space as the field delimiter with -d " ". Notice the use of back quotes (aka back ticks) which stores the output of the command inside the back quotes in the variable on the left.

Now we can do the same for the day of the month and the year. The day of the month is the third field and the year is the sixth field.

day=`date | cut -f3 -d " "`
year=`date | cut -f6 -d " "`


Now we can create the file name for our backup. 

backup_filename=/var/$day$month$year-backup.tar

Now let's calculate yesterday's date (we're assuming the script is not run on the first day of the month here) and make a variable called newer_than_date that we'll put into the tar command.

yesterday=`expr $day - 1`
newer_than_date=$yesterday$month$year


And last but not least we issue the tar command.

tar cvpf $backup_filename --newer $newer_than_date /home /etc

That's it for the script. Now to get this script to run on every day but the first day of the month we would put an entry like this into our crontab.

30 2 2-31 * * bash /root/backup_script.sh

This would run a script called backup_script.sh (in the root user's home directory) on every day of the month but the first (2 - 31 in other words) at 2:30 a.m. 

back to top

 
CBT Nuggets - IT Certification Training Videos
buy videos online fax/mailing order form contact us