% CST8207 Week 05 Notes - text editors, shell variables, start-up files % Ian! D. Allen - - [www.idallen.com] % Fall 2013 - September to December 2013 - Updated Sat Feb 1 03:45:35 EST 2014 Readings, Assignments, Labs, and ToDo ===================================== - Read (at least) these things (All The Words): - [Week 05 Notes HTML] - this file - **Read All The Words** - [Shell Variables] - [Start-Up Files] - [List of Commands You Should Know] - Using your [lynda.com] account, watch [Unix for Mac OS X Users] - **3. Working with Files and Directories** - Naming files 5m 41s - use quotes to surround names with blanks or special characters - **5. Commands and Programs** - The PATH variable 4m 13s - **7. Configuring Your Working Environment 41m 28s** - Profile, login, and resource files 9m 11s - Setting and exporting environment variables 4m 54s - Setting the PATH variable 6m 10s - using double quotes instead of single quotes Midterm Test #1 ---------------- - Midterm #1 takes place Monday, October 7 in the last hour of your lecture. - You must read the [Test Instructions] first. - [302 practice Midterm Test #1 questions] are available along with an answer key in the [Class Notes]. - A Quiz on these 302 questions is available on Blackboard. See below: Quizzes: Midterm #1 Quiz ------------------------- This is one of several quizzes in this course. Each midterm and final exam will have an associated quiz. See the course outline for the mark weight of all course quizzes, midterm tests, and exams. The quizzes are open-book, but the midterm tests and final exam are closed-book. This quiz is based on the [302 practice Midterm Test #1 questions] that are posted in the [Class Notes]. The quiz is 10 questions long and you see the answers right after you submit the quiz. You can take the quiz as many times as you like. Every time you take the quiz, you get a different random set of ten questions. This quiz closes just before the Final Exam in this course; after the Final Exam begins you will not be able to submit any more quiz attempts. Your mark for this quiz is the average of your five best quiz scores. Examples: - Your best scores: 10 10 10 10 10 10 10 9 8 7 7 4 - Your quiz mark: (10+10+10+10+10)/50 = 100% - Your best scores: 10 10 10 10 9 8 7 7 4 3 - Your quiz mark: (10+10+10+10+9)/50 = 98% - Your best scores: 10 10 10 9 8 7 7 4 3 2 - Your quiz mark: (10+10+10+9+8)/50 = 94% - Your best scores: 10 8 8 8 8 5 4 4 4 - Your quiz mark: (10+8+8+8+8)/50 = 84% - Your best scores: 10 10 8 (only three quizzes submitted) - Your quiz mark: (10+10+8+0+0)/50 = 56% Your score will be taken from the five best scores. The more times you do the quiz, the more likely you are to have a set of excellent best scores. You must have five perfect quiz scores to get a perfect averaged quiz mark. Missing quizzes (fewer than five) count as zeroes. Only the five best scores are averaged. This quiz closes just before the Final Exam in this course; after the Final Exam begins you will not be able to submit any more quiz attempts. See the “Quizzes” section in the Blackboard left side-bar for CST8207. Note: Blackboard averages the marks of *all* your quiz attempts. Your quiz mark is actually the average of your five *best* attempts, not all the attempts. Assignments this week --------------------- Check the due date for each assignment and put a reminder in your agenda, calendar, and digital assistant. - Read (All The Words), Do, and then Submit via Blackboard: - [Assignment #03 HTML] – file system commands, GLOB, redirection on the CLS - Optional BONUS assignment: [Assignment #04 HTML] – learning the VIM text editor. (Optional BONUS for extra marks.) Lab work this week ------------------ - [Worksheet #04 HTML] – GLOB Patterns and Aliases - bash GLOB patterns, alias, sum - [Worksheet #05 HTML] – I/O Redirection and Pipes - I/O redirection and pipes, date, head, nl, tail, tr, wc - [Worksheet #06 HTML] – *Optional* VIM Text Editor Practice - This is an *optional* worksheet for an optional BONUS [Assignment #04 HTML] using the `vim` text editor. - Optional Reading: [The VI (VIM) Text Editor] - Optional command-line VIM tutorial: the `vimtutor` program on the CLS. From the Class Notes link on the Course Home Page ================================================= - Review last week. Did you do everything assigned last week? From the Classroom Whiteboard/Chalkboard ======================================== - Your in-class notes go here. - Do you know your **Lab** section number? (Hint: not 400 or 410.) - Quick review of commands used in worksheets. - the `sort` command sorts one or more files to standard output - the `uniq` command removes or counts adjacent duplicate lines - the `hostname` command shows your computer’s local name - the `whoami` command shows your userid - the `wc` command has useful options to limit output - the `locate` command finds file names using an existing list - the `cut` and `awk` commands select fields in lines - the shell reads standard input: `echo date | bash` - [using GLOB patterns to match case-insensitive], e.g. `dog`, `doG`, `Dog`, `DOG`, etc. - `$ echo [dD][oO][gG]` - Using the `nano` text editor - Using the `vim` tutorial and text editor - Using `-ls` instead of `-print` with `find`, e.g. `find . -ls` - don’t use alphabetic `[a-z]` GLOB ranges until you understand Internationalization - using numeric ranges is safe: `$ echo [0-9]*` - is this directory empty? `ls` vs. `ls -a` - what is the difference between `grep` and `fgrep` ? Real Sysadmin Work ================== Here is a command pipeline that does real-time monitoring of who is trying to attack the [Course Linux Server] (requires privileged read permission on the log files): # fgrep 'refused connect' /var/log/auth.log | awk '{print $NF}' \ | sort | uniq -c | sort -nr | head -n 5 26 (202.83.48.3) 23 (70.54.33.42) 8 (183.232.32.24) 8 (114.255.20.157) 7 (82.221.103.161) The top listed attacker is from India. They tried to log in as `root`, and the `denyhosts` intrusion protection package quickly blocked that IP address: # host 202.83.48.3 3.48.83.202.in-addr.arpa domain name pointer 3.48.83.202.asianet.co.in. # fgrep '202.83.48.3' /var/log/auth.log # (output edited slightly) Oct 2 00:03:35 Failed password for root from 202.83.48.3 port 33957 ssh2 Oct 2 00:03:37 Failed password for root from 202.83.48.3 port 33957 ssh2 Oct 2 00:23:54 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 00:44:04 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 01:04:12 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 01:24:15 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 01:44:29 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 02:04:51 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 02:25:11 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 02:45:39 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 03:06:05 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 03:26:24 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 03:47:02 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 04:07:22 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 04:27:31 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 04:47:52 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 05:08:29 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 05:28:45 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 05:49:32 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 06:10:14 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 06:30:38 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 06:50:38 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 07:11:03 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 07:31:20 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 07:51:51 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 08:12:17 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 08:32:33 refused connect from 202.83.48.3 (202.83.48.3) Oct 2 08:53:29 refused connect from 202.83.48.3 (202.83.48.3) The next “attacker” is a student who forgot his password: # host 70.54.33.42 42.33.54.70.in-addr.arpa domain name pointer bas5-ottawa23-1177952554.dsl.bell.ca. The third attacker is in China: # host 183.232.32.24 Host 24.32.232.183.in-addr.arpa not found: 2(SERVFAIL) # whois 183.232.32.24 | fgrep address address: 29,Jinrong Ave, Xicheng district,beijing,100032 address: 29 jinrong ave. xicheng district, beijing China  ![Take Notes in Class] -- | Ian! D. Allen - idallen@idallen.ca - Ottawa, Ontario, Canada | Home Page: http://idallen.com/ Contact Improv: http://contactimprov.ca/ | College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/ | Defend digital freedom: http://eff.org/ and have fun: http://fools.ca/ [Plain Text] - plain text version of this page in [Pandoc Markdown] format [www.idallen.com]: http://www.idallen.com/ [Shell Variables]: 320_shell_variables.html [Start-Up Files]: 350_startup_files.html [List of Commands You Should Know]: 900_unix_command_list.html [lynda.com]: https://lyceum.algonquincollege.com/Lynda [Unix for Mac OS X Users]: http://wwwlyndacom.rap.ocls.ca/Mac-OS-X-10-6-tutorials/Unix-for-Mac-OS-X-Users/78546-2.html [Test Instructions]: 000_test_instructions.html [302 practice Midterm Test #1 questions]: practicetest1.pdf [Worksheet #04 HTML]: worksheet04.html [Worksheet #05 HTML]: worksheet05.html [Worksheet #06 HTML]: worksheet06.html [The VI (VIM) Text Editor]: 300_vi_text_editor.html [using GLOB patterns to match case-insensitive]: 190_glob_patterns.html#using-to-match-case-insensitive [Course Linux Server]: 070_course_linux_server.html [Take Notes in Class]: data/remember.jpg "Take Notes in Class" [Plain Text]: week05notes.txt [Pandoc Markdown]: http://johnmacfarlane.net/pandoc/