Fall 2008 SPR720 Sample Exam Questions

From CDOT Wiki
Jump to: navigation, search

Here are some sample questions to aid you in exam preparation. Feel free to discuss the answers on the discussion page (see link above).

1. What will the output of this script be?

#!/bin/bash 
mkdir -p /tmp/exam
cd /tmp/exam
rm -rf * 
A=0 
touch ireland spain zambia korea liberia
for N in *i*
do 
		echo $N
done 


2. What will the output of this script be?

#!/bin/bash 
mkdir -p /tmp/exam
cd /tmp/exam
rm -rf * 
touch one two three four five
chmod 0444 *
chmod a+w [ot]*
chmod u-w ??o
for NAME in one two three four five
do 
	if [ -w $NAME -a -r $NAME ] 
	then 
		echo -n $NAME " " 
	fi 
done

3. What will the output of this script be?

#!/bin/bash
echo "exrxzW" | tr "A/blCedxEzfrGyhoI=JW" "8qC3pSDehcTngi#TNrIa"

4. What will the output of this script be?

#!/bin/bash
for (( A=0; A<5; A++))
do
        echo "$A^2=" $((A * A))
done

5. Here is a Makefile:

a:      b c
        cat b c > a
d:      a e
        tar cvzf a e
clean:
        rm [ad]

Here is a listing of the files in the current directory:

$ ls -l
total 44
-rw-rw-r-- 1 chris chris 2048 2008-12-10 20:00 a
-rw-rw-r-- 1 chris chris 2019 2008-12-10 20:01 b
-rw-rw-r-- 1 chris chris   29 2008-12-10 19:59 c
-rw-rw-r-- 1 chris chris  505 2008-12-10 20:00 d
-rw-rw-r-- 1 chris chris    0 2008-12-10 19:59 e
-rw-rw-r-- 1 chris chris   58 2008-12-10 20:00 Makefile

If the command "make d" is entered, what commands will make execute? Explain why.


6. Write a python script which will ask the user for the name of a virtual machine and report whether that virtual machine is running. (Use libvirt).

7. Write a bash script which will print all of the files in your home directory which end in .ps -- you must be able to run the script from any directory.

8. Write a spec file for an RPM package. Here are the package details:

  • The source files are in a single file called foo-3.0.tar.bz2, which is released under the BSD license, according to the files NOTES.TXT and LICENSE which are inside that tarball.
  • The software is a graphical strategy game which should be in the package group "Applications/Games". The homepage for the software is http://foo.example.com
  • The software successfully builds from source on a freshly-installed Fedora 9 system using just the commands "make" and "make install". The build process requires Perl. The only files installed are binaries, which are placed in /usr/bin.

Note: you may use the 'rpmdev-newspec' tool to create a skeleton specfile, and then use that specfile in your answer.

8. Describe the purpose of the Name, Release, BuildRequires, Source, and Requires fields in an RPM spec file. Give examples.

9. What is a package repository (as used by yum)? How do you create one? How does yum get files from a repository?

10. Describe in detail and give an example of each of the three types of pathnames used in the bash shell.

11. What is the difference between an interpreted and a compiled language? Which category do these scripting languages belong to?: bash, python, make

12. Why is it better to login to remote computers using ssh instead of telnet?

13. What command would you use to set the permission on a script so that only the script's owner could execute it? All other users should have no access to the script.

14. Write the correct bash syntax to run the command "foo", taking the input from the file "hot", placing the output in the file "cold", and placing error message in the file "warm".

15. Write the correct bash syntax to run the command "bar", taking the input from the file "up", and sending the output and error messages to the command "baz".

16. Write a bash script to display all of the odd numbers from 1 to 99 with one space between each number.

17. Describe what the PATH environment variable does. Write the syntax to add the directory "/usr/local/bin" to the PATH as the first directory searched.

18. What will this command do to the existing file "ocean"? date >ocean

19. What will this command do to the existing file "sea"? date >>sea

20. What will this command do if the file "lake" does not exist? date >lake

21. What will this command do if the file "stream" does not exist? lpr <stream

22. What is wrong with this command pipeline? How would you fix it? cat /usr/share/dict/words >/tmp/x | grep -i "[aeiou]" <<wc | wc -l

23. Write a bash script which asks the user for a one-line message and an e-mail address, then converts the message to uppercase and mails it to the address specified.