System Administration HW3 - Shell Script
260 likes | 301 Views
This assignment covers scripts for user connect time statistics, spamming system with customized mails, and GUI port manager using dialogs. Learn to manage system resources effectively.
System Administration HW3 - Shell Script
E N D
Presentation Transcript
Requirements • User connect time statistic script (10%) • Use one-line command to show user connect time statistic. • Spamming system (40%) • Send massive mails with customized template and database. • GUI port manager (50%) • Manage your ports with dialog boxes.
User Connect Time Statistic Script – Requirements (1/2) • Use one-line command • The following lines should NOT be counted • User still logged in • shutdown, reboot or other msgs not associated with accounting • log file location • Use environment variable ‘LOG_FILE’ • Default to /var/log/utx.log • Results should be sorted by time • Output format • USER TIME (in seconds)
User Connect Time Statistic Script – Requirements (2/2) • Only pipes (cmd | cmd) and backquotes (`cmd`) are allowed • No temporary files or shell variables (except LOG_FILE) • No “&&” “||” “>” “>>” “<“ “;” “&”
User Connect Time Statistic - DEMO • Hint: $ man last
Spamming System – Sendmail • $ sendmail –t < letter • Sample letter • sendmail(8), base64(1) From: =?UTF-8?B?6auY5omLCg==?=<hchung@cs.nctu.edu.tw> To: =?UTF-8?B?5Y6y5a6zCg==?= <hwchiu@cs.nctu.edu.tw> Subject: =?UTF-8?B?6auY5omL5Y6y5a6z5LiN57Ch5ZauCg==?= Content-Transfer-Encoding: base64 Content-Type: text/plain; charset=utf-8 5L2g5piv6auY5omL5L2g5Y6y5a6zCuaIkeaYr+mCsea4o+S4jeewoeWWrgo=
Spamming System – Requirements (1/3) • $ hw2 [-hv] [-f from_address] [-F from_name] [-s subject] [-c content_file] -t table_file • If neither –f nor –F is provided, use default sender. • Show usage and exit if running with invalid or –h option. • Use –c option to read content from “file” instead of “stdin”. • In –v mode, print out letter instead of sending. • UTF-8 should be supported. • There will be escaped characters in subject and content_file. • %i should be replaced by elements in the table_file • Do NOT need to implement fool-proof.
Spamming System – Requirements (2/3) • Table file • %1 is recipient’s address • %2 is recipient’s name • Use “\t” to split columns • No specific table size %3 %2 計算機系統管理學期成績 %3%2 同學您好, 您的 計算機系統管理 學期成績為 %4分, %5 及格。 若對成績有疑問請直接回信到ta@nasa.cs.nctu.edu.tw。 SA助教關心您! Content file and subject (contains escaped characters %i) Table file (uses “\t” as delimiter) %1 %2 %3 %4 %5 hchung@cs.nctu.edu.tw 鍾 翔 0156038 99 有 hwchiu@cs.nctu.edu.tw 邱宏瑋 0156521 55 沒有
Spamming System – Requirements (3/3) • hw2.sh -f sata@nasa.cs.nctu.edu.tw -F "計算機系統管理助教“ -s "%3 %2 計算機系統管理學期成績" -c demo_c -t demo_t • http://nasa.cs.nctu.edu.tw/sysadm/hw3/demo_t • http://nasa.cs.nctu.edu.tw/sysadm/hw3/demo_c • http://nasa.cs.nctu.edu.tw/sysadm/hw3/output Example options Sample result
Spamming System – DEMO • Hint • getopt(1)
My Ports Manager – Requirement (1/2) • Use sudo to add/delete ports • Clean all temp files • Use dialog on Freebsd 9 • Fool-proof
My Ports Manager – Requirement (2/2) • Flow • List • Manage • Choose SEVERAL ports • Show dependency • Required by who • Remove • Exit • Install • Prefix • Choose ONE port • By binary • By source • Exit • Exit
My Ports Manager – Hint • dialog(1) • ports-mgmt/pkg_tree • pkg_info, pkg_delete, pkg_add • make install clean BATCH=yes • /usr/ports/INDEX-9 • xargs
Hand-in • Due & Demo • 2012/11/20
Help IRC channel #nctuNASA on freenode Newsgroup cs.course.sysadmin BBS bs2.to board CS-SysAdmin Email ta@nasa.cs.nctu.edu.tw Goto CSCC to ask professional 3F!