system administration hw3 - shell script

13
System Administration System Administration HW3 HW3 - Shell Script - Shell Script chenyp

Upload: len-horn

Post on 04-Jan-2016

47 views

Category:

Documents


7 download

DESCRIPTION

System Administration HW3 - Shell Script. chenyp. Requirements. File statistics (20%+10%) use one-line command to show files statistics Bonus(10%) script (20%) Write a shell script to parse log. A simple search platform (60%). File statistics. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: System Administration HW3 - Shell Script

System Administration HW3System Administration HW3- Shell Script- Shell Script

chenyp

Page 2: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

2

Requirements

File statistics (20%+10%)• use one-line command to show files statistics

• Bonus(10%)

script (20%)• Write a shell script to parse log.

A simple search platform (60%)

Page 3: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

3

File statisticsFile statistics

Use one-line command to show File statistics. 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)

All commands should be concatenated using "|"(pipe) in one line.

Can not create temporary file. If the number of the largest or the smallest is more than one,

choose the last one. No “&&” “||” “>” “>>” “<“ .

Page 4: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

4

File statisticsFile statistics

Examples: % ls –l -rw-r--r-- 1 chenyp gcs 720 Nov 14 18:25 test -rw-r--r-- 1 chenyp gcs 720 Nov 14 16:55 test_a -rw-r--r-- 1 chenyp gcs 378 Nov 10 17:12 test_b -rw-r--r-- 1 chenyp gcs 397 Nov 13 16:59 test_c -rw-r--r-- 1 chenyp gcs 536 Nov 12 17:43 test_d -rw-r--r-- 1 chenyp gcs 191 Nov 14 17:25 test_e

% ./hw3_1.sh

Bonus(10%)• If you can do it with subdirectories, you will get extra 10%.

2222Max: test_a 720 chenypMin: test_e 191 chenyp

Page 5: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

5

scriptscript

Write a script to parse log for ssh bruteforce. Print the IP address and times descending. 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

Page 6: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

6

scriptscript

SSH bruteforceOnly 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 bsd1 sshd[6587]: error: PAM: authentication error for illegal user onlyeric23 from 140.113.246.1

Example• % Parserlog.sh –n 3 –f /tmp/logfile• 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

Page 7: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

7

A simple search platformA simple search platform

Write a user-friendly search platform by using dialog(1) First, you should show a welcome message.

Page 8: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

8

A simple search platformA simple search platform

Second, you should use menubox for client to choose which service to provide.

Page 9: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

9

A simple search platformA simple search platform

Basic search:• Input a keyword.

• Go to the wiki and show the first introduction for the keyword.

Page 10: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

10

A simple search platformA simple search platform

Advanced search:• Input a keyword.

• Show the content for the keyword and use checklist to choose which information to display.

Page 11: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

11

A simple search platformA simple search platform

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.bz2

• The keyword.tar.bz2 contains the files client chosen.

• Java.tar.bz2 contains geography.txt history.txt Notes.txt Externel_links.txt

Page 12: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

12

A simple search platformA simple search platform

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.bz2.

• Example: You should display the content of the

– geography.txt

– history.txt

– Notes.txt

– Externel_links.txt

If you choose the java.tar.bz2.

Page 13: System Administration HW3 - Shell Script

Com

pu

ter C

en

ter, C

S, N

CTU

13

HelpHelp

IRC channel #nctuNASA on freenode Newsgroup cs.course.sysadmin BBS bs2.to board CS-SysAdmin Email [email protected] Goto CSCC to ask professional 3F!