System Administration HW 3 Shell Script chenyp Computer

  • Slides: 13
Download presentation
System Administration HW 3 - Shell Script chenyp

System Administration HW 3 - Shell Script chenyp

Computer Center, CS, NCTU 2 Requirements q File statistics (20%+10%) • use one-line command

Computer Center, CS, NCTU 2 Requirements q File statistics (20%+10%) • use one-line command to show files statistics • Bonus(10%) q script (20%) • Write a shell script to parse log. q A simple search platform (60%)

Computer Center, CS, NCTU 3 File statistics q Use one-line command to show File

Computer Center, CS, NCTU 3 File statistics q Use one-line command to show File statistics. q Print the sum of files’ size in the directory, find the largest and the smallest files, and print its filenames, filesizes and owners. (not include subdirectories) q All commands should be concatenated using "|"(pipe) in one line. q Can not create temporary file. q If the number of the largest or the smallest is more than one, choose the last one. q No “&&” “||” “>>” “<“.

Computer Center, CS, NCTU File statistics q Examples: q % ls –l q q

Computer Center, CS, NCTU File statistics q Examples: q % ls –l q q q -rw-r--r-- 1 chenyp -rw-r--r-- 1 chenyp gcs gcs gcs 720 Nov 14 18: 25 test 720 Nov 14 16: 55 test_a 378 Nov 10 17: 12 test_b 397 Nov 13 16: 59 test_c 536 Nov 12 17: 43 test_d 191 Nov 14 17: 25 test_e q %. /hw 3_1. sh 2222 Max: test_a 720 chenyp Min: test_e 191 chenyp q Bonus(10%) • If you can do it with subdirectories, you will get extra 10%. 4

Computer Center, CS, NCTU script q Write a script to parse log for ssh

Computer Center, CS, NCTU script q Write a script to parse log for ssh bruteforce. q Print the IP address and times descending. q Syntax • Parserlog. sh [-n number] –f file • -n Ø Show the most Nth times and its ip address. Ø If n is none, show all and sorted by times descending. • -f Ø Log file Ø Sample file: – http: //nasa. cs. nctu. edu. tw/logfile 5

Computer Center, CS, NCTU script q SSH bruteforce Only parse these three formats Nov

Computer Center, CS, NCTU script q SSH bruteforce Only parse these three formats Nov 15 13: 53: 32 NASA sshd[12397]: Invalid user supporte from 84. 73. 134. 84 Nov 15 13: 53: 35 NASA sshd[12399]: Invalid user soporte from 84. 73. 134. 84 Nov 15 21: 45: 25 NASA sshd[16601]: error: PAM: authentication error for root from 122. 229. 6. 189 Nov 15 22: 00: 36 NASA sshd[16765]: error: PAM: authentication error for root from 115. 186. 131. 106 Nov 15 22: 16: 40 NASA sshd[16868]: error: PAM: authentication error for root from 67. 206. 169. 146 Nov 15 22: 31: 59 NASA sshd[16964]: error: PAM: authentication error for root from 74. 238. 205. 245 Nov 15 22: 47: 22 NASA sshd[17129]: error: PAM: authentication error for root from 70. 247. 71. 201 Nov 15 16: 28: 15 bsd 1 sshd[6587]: error: PAM: authentication error for illegal user onlyeric 23 from 140. 113. 246. 1 q Example • % Parserlog. sh –n 3 –f /tmp/logfile • • • 6 70. 247. 71. 201 7 times 82. 207. 96. 161 6 times 208. 124. 238. 246 5 times 115. 186. 131. 106 5 times 140. 113. 47. 207 5 times 95. 155. 122. 12 5 times

Computer Center, CS, NCTU 7 A simple search platform q Write a user-friendly search

Computer Center, CS, NCTU 7 A simple search platform q Write a user-friendly search platform by using dialog(1) q First, you should show a welcome message.

Computer Center, CS, NCTU 8 A simple search platform q Second, you should use

Computer Center, CS, NCTU 8 A simple search platform q Second, you should use menubox for client to choose which service to provide.

Computer Center, CS, NCTU 9 A simple search platform q Basic search: • Input

Computer Center, CS, NCTU 9 A simple search platform q Basic search: • Input a keyword. • Go to the wiki and show the first introduction for the keyword.

Computer Center, CS, NCTU 10 A simple search platform q Advanced search: • Input

Computer Center, CS, NCTU 10 A simple search platform q Advanced search: • Input a keyword. • Show the content for the keyword and use checklist to choose which information to display.

Computer Center, CS, NCTU A simple search platform q Mergedata • Input a keyword.

Computer Center, CS, NCTU A simple search platform q Mergedata • Input a keyword. • Show the content for the keyword and use checklist to choose which information to merge. • You should merge files to the wikimerge/keyword. tar. bz 2 • The keyword. tar. bz 2 contains the files client chosen. • Java. tar. bz 2 contains Ø geography. txt Ø history. txt Ø Notes. txt Ø Externel_links. txt 11

Computer Center, CS, NCTU A simple search platform q Show mergedata • First, you

Computer Center, CS, NCTU A simple search platform q Show mergedata • First, you should display which files in the wikimerge/ and use menubox for client to choose. • And show all the content in the keyword. tar. bz 2. • Example: Ø You should display the content of the – – geography. txt history. txt Notes. txt Externel_links. txt Ø If you choose the java. tar. bz 2. 12

Computer Center, CS, NCTU 13 Help q IRC channel #nctu. NASA on freenode q

Computer Center, CS, NCTU 13 Help q IRC channel #nctu. NASA on freenode q Newsgroup cs. course. sysadmin q BBS bs 2. to board CS-Sys. Admin q Email ta@nasa. cs. nctu. edu. tw q Goto CSCC to ask professional 3 F!