Talk:Fall 2008 SPR720 Sample Exam Questions
Here are some sample questions to aid you in exam preparation. Feel free to discuss the answers on the discussion page (see link above).
Contents
- 1 1. What will the output of this script be?
- 2 2. What will the output of this script be?
- 3 3. What will the output of this script be?
- 4 4. What will the output of this script be?
- 5 5. Here is a Makefile:
- 6 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 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 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".
- 9 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".
- 10 16. Write a bash script to display all of the odd numbers from 1 to 99 with one space between each number.
- 11 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.
- 12 18. What will this command do to the existing file "ocean"? date >ocean
- 13 19. What will this command do to the existing file "sea"? date >>sea
- 14 20. What will this command do if the file "lake" does not exist? date >lake
- 15 21. What will this command do if the file "stream" does not exist? lpr <stream
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
ANSWER
ireland spain zambia liberia
Nes
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
ANSWER
one three
Nes
3. What will the output of this script be?
#!/bin/bash echo "exrxzW" | tr "A/blCedxEzfrGyhoI=JW" "8qC3pSDehcTngi#TNrIa"
ANSWER
Seneca
Nes: tr is an translator, it will use the first one to match the second string.. A/blCedxEzfrGyhoI=JW 8qC3pSDehcTngi#TNrIa
- say, if u pipe is "A/B", then out put is "8qC", if the pipe is "ACxEW", then output will be "8peha"
4. What will the output of this script be?
#!/bin/bash for (( A=0; A<5; A++)) do echo "$A^2=" $((A * A)) done
ANSWER
0^2= 0 1^2= 1 2^2= 4 3^2= 9 4^2= 16
Nes
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.
ANSWER
It will call up the function "d" in Makefile, and function "d" will call-up function "a", then function "a" will run print out the content of file "b" and "c" into a file called "a" then, at the end of function "d", it will tar (with compress) file "a" to a tar file called "e"
Why? -- There is something that specifically triggers the target 'a' ... also, careful with terminology, use 'target' and 'dependency' -CT
Nes
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).
ANSWER
#!/usr/bin/python import libvirt vm_Name=str(raw_input("Please enter your virtual machine's name: ")) conn=libvirt.open(None) try: vm=conn.lookupByName(vm_Name) try: vm_id=vm.ID() print "Yes, your vm is up and running. The ID is ", vm_id except: print "Your vm is defined, but not running." except: print "Sorry, your vm is not running."
Nes.. finally.. i did it.. @@ Nes: edit at 00:53, as CT suggested.
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.
#!/bin/bash find ~ -name "*.ps" Save the script, give it executabel permission. PATH="$PATH:."
Actually, I meant print as in send them to the printer. -CT
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".
ANSWER:
cat < hot > cold 2>warm (I use cat instead of "foo")
PopCon
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".
cat < up > baz 2>&1 (again I use cat instead of "bar")
PopCon
16. Write a bash script to display all of the odd numbers from 1 to 99 with one space between each number.
ANSWER:
#!/bin/bash for ((A=1; A<=99; A+=2)) do echo -n $A" " done
PopCon
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.
ANSWER: Nes: PATH is a variable that tell where the shell what path to search when a command was requested to run.
PATH=$PATH:/usr/local/bin
18. What will this command do to the existing file "ocean"? date >ocean
Answer
Nes: It will redirect standard output of command "date" to the file "ocean". The file "ocean" iwll be replaced.
19. What will this command do to the existing file "sea"? date >>sea
Answer
Nes: It will redirect standard output of command "date" and append to the file "sea". The newer output will be writen at the end of the file "sea".
20. What will this command do if the file "lake" does not exist? date >lake
Nes: The command will redirect the standard output of command "date" into a new created file "lake"
21. What will this command do if the file "stream" does not exist? lpr <stream
Nes: It will capture standard output and save it to the file "stream", then the command "lpr" will put it in the print queue.
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.