Homework 5
Purpose:
First contact with shell scripting.
Look through the manual pages of the commands you use and try to
understand some of the options.
Try to use as many shortcuts you discovered in Homework 1-3 as
possible (copy&paste, Up Arrow, TAB, etc). Typing is a waste of
time.
1. Open several terminal windows and a web browser displaying this
page.
2. Run "top" in one of the terminal windows and keep an eye on what
happens to the memory and cpu load as you perform the next
exercises.
3. Make a directory named test-a, go into that directory, create 9
files named a1.txt - a9.txt each containing a random number (hint:
use $RANDOM associated with echo).
4. Create a file named aa.txt containing all the numbers in the
previous files, one on a line (hint: use cat associated with
wildcards). Do that using only one command.
5. Go outside test-a and remove that directory.
6. Write a shell script named maketest.sh that will do the same as
exercises 3 and 4 (hint: copy the commands in a file, add the magic
number, make it executable, execute it). Did you have any problems
while trying to execute it?
7. Modify your script to use "a" as an argument to the script, e.g.
"maketest.sh a".
8. Add comments to your shell script.
9. Try to make the script as scalable as possible (e.g. to be able
to create "any" number of files just by changing one parameter
inside or an argument). Comment on the range of "any" and how
complicate becomes to implement that. Don't run a script that will
create more than 5000 files, go gradually to that number and see
what problems you encounter. Don't forget to delete the directory
after each run.
10. Try a "parallel" version of the script where you spawn several
processes that will write files. Keep the total number of files
under 1000.
11. Search online for "GNU parallel", read the documentation, and
see if you can apply it to your task.