Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Create a script backup.sh which contains a command to create a compressed archive of the work subdirectory. You will need to create the backup.sh

1. Create a script backup.sh which contains a command to create a compressed archive of the work subdirectory. You will need to create the backup.sh file and give it the appropriate permission. The contents will need a shebang line and a tar command; you might like to add an echo to confirm that the script is running. The tar command can be modelled on those you used earlier. You will need to give the name of the directory to compress, and choose a sensible filename for the archive that is produced. Once the script is written, you should test that it runs and does what you wish.

2. Create the following scripts and test them out.

hello2.sh:

#!/bin/bash name="Ali" echo "Hello $name, have a nice day!"

hello3.sh:

#!/bin/bash echo "Who is there?" read name echo "Hello $name, have a nice day!"

hello4.sh:

#!/bin/bash echo "Hello $1, have a nice day!"

Give one command-line argument, for example ./hello4.sh Ali

hello5.sh:

#!/bin/bash today=$(date) echo "Hello, the date and time is $today." echo "The date is $(date -I)."

3. Adapt your backup script so that the directory is set by a variable. Then adapt it again to use a command-line parameter.

Remember that $ is required to use the value of a variable. Does your script back up the correct directory? Is the backup file named appropriately?

4. Adapt your backup script so that the filename used for the backup file includes today's date in addition to the directory name.

The date man page has many options for obtaining and formatting the date; the -I(capital i) option used previously is suitable.

Avoid constructing a filename that contains spaces. You could use - (hyphen) instead; for example, "my-dir-2020-12-25.tgz" rather than "my dir 2020 Dec 25.tgz".

Beware of ambiguity when combining variable names with literal strings. For example "my $var value" is fine, but "my$varvalue" may not mean what was intended; an alternative syntax "my${var}value" can be used to remove ambiguity.

Use double quotes for strings containing variables: single-quoted strings are taken literally.

5. Create a script that will back up several directories. To reduce clutter, the script should move the backup files into a subdirectory called backups.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions