Surname, Name: Section: Student No: Closed Book, closed note exam. You are required to write down commands with necessary arguments and options; and make sure that they work. Your script and output should match. Give the best result that you can give! Each question worths 5 points unless otherwise stated. Over 100 points is bonus. Unless otherwise stated for question k, your answers as command must be in k.sh and output should in k.txt both should be in Answers directory. You can combine k.sh s in a single file such as cevaplar.sh SIGNATURE....... Time of Submission: Prelude: Before solving questions you should: let NAME be your FirstLast name as ascii (MAkgul, ASOzgur, LMessi, LionelMessi) create NAME and NAME/Answers directories mkdir -p /NAME/Answers script NAME/NAME.Log download the questions file and unzip it in NAME Directory, ( maintaining directory structure), unzip file-path cd /NAME use wget http://lab1t.ctis.bilkent.edu.tr/download/labm.zip Your working directory could be LabQ, files that you operate on will be in LabQ. Your answers will be written under NAME; shell scripts and solution files under NAME/Answers; you need to redirect selected output to NAME/Answers directory. You can write your commands within k.sh for question k OR cevap.sh by identifying your questions If you put output of question k in LABQ, use k.txt as the answer file. When you finish, you will zip NAME directory with command cd ; zip -r NAME NAME upload NAME.zip 1. <GroupA> apply mkdir -p /NAME/Answers/Dir{1,2,3,4,5,6}. For the rest of this question your are located in LabQ ( 3 pts each ) copy everything under LabQ into Answers/Dir6 using cp. You might have hidden files/directories. Give command within LabQ and use relative addressing cp -R.../Answers/Dir6 copy everything under LabQ including directory name into Answers/LabQ using cp. You might have hidden files/directories. Give command within LabQ and use relative addressing cp -R../LabQ../Answers/ copy everything in LabQ into Dir1 with rsync. Keep owner and date info rsync -av.../answers/dir1 do it with tar without using any auxiliary file into Dir2 tar cf -. ( cd../answers/dir2;\ tar xf - ) do it with tar using any auxiliary (tar) file into Dir3. Keep the file under NAME tar cf../dir3.tar. ; cd../answers/dir3 ; tar xvf../../dir3.tar do it with cpio without using any auxiliary file into Dir4 find. cpio -pd../answers/dir4 a do it with cpio using any auxiliary (cpio) file into Dir5. Keep the file under NAME find. cpio -o >../Dir5.cpio ; cd../answers/dir5 ; cpio -id <../../Dir5.cpio </GroupA> 20/Nov/2012 CTIS486 Midterm I 1
2. Combine all *.txt files in the current directory hierarchy! (storing in Answers/ALLX.TXT ) and determine number of lines containing word Net case insensitive in all *.txt files find. -type f -name "*.txt" xargs cat >>../Answers/ALLX.TXT OR find. -type f - name "*.txt" -exec cat {} \; >../Answers/ALLX.TXT OR find. -type f - name "*.txt" -exec cat {} >>../Answers/ALLX.TXT \; then grep -iwc Net../Answers/ALLX.TXT 3. Given a.txt: determine lines containing word Fox followed by word Net, not necessary immediately grep "Fox.*Net" a.txt will find String Fox followed by Net in a.txt. To find word Fox and Net we need: grep "\<Fox\>.*\<Net\>" a.txt 4. Given A.txt we want to: (each 2 ) - Vi/Vim. On lines containing internet, replace Fox with FireFox Give command and write file as Answers/A2.TXT vi A.txt :g/internet/s/fox/firefox/g :w../answers/a2.txt :q! - Sed On lines containing internet, replace Fox with FireFox Give command and write file as Answers/B2.TXT sed /internet/s/fox/firefox/g A.txt >../Answers/B2.txt 20/Nov/2012 CTIS486 Midterm I 2
5. suppose you own bilet.net domain. You have machines ayse.bilet.net (70.80.90.100), fatma.bilet.net (80.90.100.110), and filiz.bilet.net(60.70.80.90). You have contact with ank.bilxyz.net (139.179.139.179), and van.xyz.net.tr (195.95.95.95). You want ayse, fatma and filiz to serve as http://bilet.net and http://www.biet.net. Moreover, you want ayse to serve as http://satis.bilet.net and fatma as http://video.bilet.net/, and filiz http://anket.bilet.net/. You want your master DNS/NS server filiz machine and slave machines fatma and van. ayse and fatma will be main MX machines and backup will be filiz and ank machines. More over, you want halk sub-domain with NS servers fatma (master) and van (slave). Write down complete zone file for bilet.net 20 pts ; znoe file bilet.net pm machine filiz.bilet.net $TTL 86400 @ IN SOA filiz.bilet.net. hostmaset.bilet.net ( 2012112000 6H 2H 2W 1H ) ; IP for http://bilet.net IN A 70.80.90.100 IN A 80.90.100.110 IN A 60.70.80.90 IN NS filiz IN NS fatma IN NS van.xyz.net.tr. ; IN MX 10 ayse IN MX 10 fatma IN MX 20 filiz IN MX 20 ank.bilxyz.net. ; IP s for www www IN A 60.70.80.90 IN A 70.80.90.100 IN A 80.90.100.110 ; filiz IN A 60.70.80.90 ayse IN A 70.80.90.100 fatma IN A 80.90.100.110 ; anket IN A 60.70.80.90 satis IN A 70.80.90.100 video IN A 80.90.100.110 ; alternatively ;anket IN CNAME filiz ;satis IN CNAME ayse ;video IN CNAME fatma ; sub-domain halk.bilet.net halk IN NS fatma IN NS van.xyz.net.tr. 6. write part of named.conf for fatma machine file (using the above info ) 5 pts part of named.conf or named.conf.local on machine fatma zone "halk.bilet.net" { type master; file "db.halk-bilet-net"; }; 20/Nov/2012 CTIS486 Midterm I 3
zone "bilet.net" { type slave; file "SEC.bilet-net"; masters { 60.70.80.90;} ; }; 7. Given the following file (data.txt) for a certain course lab mid1 mid2 final Name (aciklama) 30 45 70 50 Ali 40 60 40 80 Ayse 80 80 60 80 Filiz 50 40 90 20 Fatma 60 70 50 70 Elif aciklama is for information. It is not part of data.txt For each student we want compute weighted sum 0.15*lab+0.20*mid1 + 0.25 * mid2 + 0.4 * final. We want to assign grades as A if sum 80, B if 60 sum < 80, and D if sum < 60 (for simplicity). write an Awk script to compute weighted sum, grade and print name grade into file data1.txt, and compute and print number of A, B, D s 10 pts Awk.1 for this problem {sum=0.15*$1+0.20*$2+0.25*$3+0.4*$4} sum >= 80 {na=na+1; print $5, "A" } (sum < 80 ) && (sum >= 60) {nb=nb+1; print $5, "B" } sum < 60 { nd=nd+1; print $5, "D" } END{ print "# of A =", na, " # of B =", nb, " # of D =", nd } awk -f Awk.1 data.txt will give the result 8. Given data2.txt containing names and grades in certain course final Ali 65 Ayse 62 Filiz 74 Fatma 47 Elif 63 find the largest and smallest grade and names of the corresponding students. (assume they are unique); sort -n -k2,2 data2.txt will sort the lines accoring to second column from lowest to highest. Thus sort -n k-2.2 data2.txt tail -1 awk { print "Highest ", $0 } and sort -n k-2.2 data2.txt head -1 awk { print "Lowest ", $0 } find mean of grades and number of students Awk.2 will give the result via awk -f Awk.2 data2.txt where Awk.2 is: {sum=sum+$2} END{ print "mean ", sum/nr, " of ", NR, " students " } find median and corresponding student name (median is, for a group of 5, 3rd element of the sorted list). ( For simplicity assume NR = 5. ) You need to read median line of the sorted file: sort -n -k2,2 data2.txt sed -n 3p awk {print "median ", $2, " ", $1 } if number of lines is 2k-1 you need kp in the above construction. instead of 3p 20/Nov/2012 CTIS486 Midterm I 4
Your answers should look like the following. Your scripts/commands should work for any size data2.txt. You may assume for median number of students is odd, Your are free to use any program: bash, awk, sed, sort, etc. 10 pts Highest 74 Filiz Lowest 47 Fatma Mean 62.2 of 5 students Median 63. Elif 9. In bilet.com, a message addressed to bilgi@bilet.com, will be distributed as: i) to users: webmaster, boss, arge-group and satis-group. Ar-ge group contains, ayse, fatma, elif, burak and satis-group contains ali, ahmet, sinem, and derya. A copy of all mail for satis-group is stored in /home/satis/logs/satis.log ii) a copy of the message is appended to /usr/local/logs/bilgi.log iii) message is passed to program /usr/sbin/bin/auto-respond to send an acknowledgment to sender Write corresponding entry for /etc/aliases file. bilgi: webmaster, boss, arge-group, satis-group, bilgi-log, bilgi-cevap arge-group: ayse, fatma, elif, burak satis-group: ali, ahmet, sinem, derya, /home/satis/logs/satis.log bilgi-log: /usr/local/logs/bilgi.log 10. On machine elif.xyz.net you want all mail will go as xyz.net. This machine will also host domain bilxyz.com, gokyuzu.org. All mail to gokyuzu.org will be delivered to gokyuzu@gmail.com and to gokyuzu user. For domain bilxyz.com, only mail for webmaster@bilxyz.com will be accepted and will be delivered to bilxyz user. Write necessary configurations in suitable files: identify files and corresponding lines. 15 pts #/etc/postfix(main.cf myhostname=elif.xyz.net mydomain=xyz.net myorigin=$mydomain mydestination=elif.xyz.net xyz.net localhost.xyz.net ftp.xyz.net www.xyz.net virtual_alias_domains = bilxyz.com gokyuzu.org 3 virtual_alias_maps = hash:/etc/postfix/virtual #/etc/postfix/virtual @gokyuzu.org gokyuzu-all webmaster@bilxyz.com bilxyz #/etc/aliases gokyuzu-all: gokyuzu, gokyuzu@gmail.com you shold run also newalias and postmap virtual $ in /etc/postfix 11. How would see list of public rsync archives/modules at rsync server ftp.linux.com? How would you download directory pardus/2012/iso/ at rsync archive of ftp.linux.com into iso directory in your home? Assume your at your home directory. complete the command: rsync rsync://ftp.linux.com/... To see all public rsync modules: rsync ftp.linux.com:: rstnc -av ftp.linux.com::pardus/2010/iso/. Wth the rsync protocol notation: rsync rsync://ftp.linux.com/pardus/2010/iso. 12. Write basic part of rsyncd.conf for public archive books which will ve stored at /usr/local/book with permissions of user ftp. Public archive means anybody can read download, but can not upload anything. 20/Nov/2012 CTIS486 Midterm I 5
13. Given mail.txt containing e-mail, grade and Full Name of stuents: ali@ctis.bilkent.edu.tr A Ali Veli Net ayse@gmail.com B Ayse Kirmizi fatma@yahoo.com C Fatma Maviy Net burak@hotmail.com D Burak Kara Batmaz filiz@yandex.com A Filiz Ali Yazar ahmet@ug.bilkent.edu.tr C Ali Ahmet Kitap Okur Write a bash script, say mail.sh, which will read mail.txt and send mail to students with Subject: your grade, and in the body it will say Dear Ali Veli, Your grade for CTIS123 will be A. Best Regards The Management For the first students. You can use binaries /bin/mail, /bin/mailx, or /usr/sbin/sendmail #!/bin/bash while read address grade name do mailx $address -s "Your Grade " <<END Dear $name Your grade for CTIS123 will be $grade Best Regards The Mangement END done < mail.txt 14. Write a Bash script which will take a a set of arguments. For each one it will do the following: -; check whether it exists, if not will give a message and continue. If it exists, and if it is directory, it will print output of du -s DIR If it is file it will print its size. Else it will print it is not a file or directory and continua 10. File.sh is: #!/bin/bash for file do nesne=$file if! [ -e $nesne ] then echo "$nesne does not exit " continue fi if [ -f $nesne ] 20/Nov/2012 CTIS486 Midterm I 6
then set -- $( ls -ld $nesne ) echo "size of $nesne is $5 " elif [ -d $nesne ] then cd $nesne volume=$( du -s. ) echo "disk usage of $nesne is $volume " else echo "$nesne is neither a file nor a directory" fi done./file.sh File.sh. /dev/sda /yok/yok aan example call of File.sh 15. Assume you have several hundred picture files with suffix JPEG in the current directory. Suppose program jpg2png will transform a jpg file into png file (as jpg2png <a > b will obtain from jpeg file a, png file b). You want to transform all files with suffix into png files with suffix jpg (i.e. from file a.jpeg we will obtain a.png). write a bash script for this purpose. for file in *.JPEG do new=${filw(jpeg/png} jpg2png < $file >$new done 20/Nov/2012 CTIS486 Midterm I 7