% CST8207 Week 05 Notes – Redirection, Variables, Start-up Files, Midterm #1 % Ian! D. Allen – – [www.idallen.com] % Fall 2014 - September to December 2014 - Updated Sun Jan 4 12:54:30 EST 2015 Readings, Assignments, Labs, and ToDo ===================================== - Read (at least) these things (All The Words): - [Week 05 Notes HTML] – this file – **Read All The Words** - [Unix Shell I/O Redirection (including Pipes)] - [Shell Variables] - [Start-Up Files] - [List of Commands You Should Know] - [Video Tutorials on Lynda.com] - 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 and Quiz ------------------------- - Midterm #1 takes place Friday, October 3 (end of Week 5) in your scheduled lecture hour (not in your lab period). - See the [Week 04 Notes HTML] for details about the test and the quiz. - Do you know your **Lab** section number? (Hint: not 010 or 020.) Assignments and Lab work 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 #02 HTML] – simple file system commands on the CLS - Coming soon: Assignment #04 HTML – GLOB and redirection - Really do **Read All The Words**. You don’t get a second chance to get it right. ### Worksheets The worksheets are available in four formats: Open Office (ODT), PDF, HTML, and Text. Only the Open Office format allows you “fill in the blanks” in the worksheet. The PDF format looks good but doesn’t allow you to type into the blanks in the worksheet. The HTML format is crude but useful for quick for viewing online. Do **NOT** open the ODT files using any Microsoft products; they will mangle the format and mis-number the questions. Use the free Libre Office or Open Office programs to open these ODT documents. On campus, you can [download Libre Office here]. - [Worksheet #02 HTML] – Using standard Linux commands I - `PS1, cd, find, less, ls, man, mkdir, passwd, pwd, rmdir` - [Worksheet #03 HTML] – Using standard Linux commands II - `cat, clear, cp, find, grep, history, less, man, mv, rm, sleep, touch` - [Worksheet #04 HTML] – GLOB Patterns and Aliases - bash GLOB patterns (wildcards), `alias, sum` - [Worksheet #05 HTML] – I/O Redirection and Pipes - bash I/O redirection (including pipes), `date, head, nl, tail, tr, wc` ### Optional Bonus VIM Assignment – extra marks - [Assignment #03 HTML] – *Optional* VIM Text Editor Practice - this is an *optional* worksheet for a BONUS assignment using `vim` - Optional Reading: [The VI (VIM) Text Editor] - [Worksheet #06 HTML] – *Optional* VIM Text Editor Practice - this is an *optional* worksheet for a BONUS assignment using `vim` - Optional command-line VIM tutorial: the `vimtutor` program on the CLS. - Video tutorial introduction to VIM (part one) from Kyle: 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 ======================================== - **Take notes in class!** Your in-class notes would go here. - Finishing redirection and pipes this week. - No man page for `bash` built-in commands `cd`, `alias`, `history`, etc. - use the `help` built-in command: `help alias` - Coming soon: I propose we ban open devices in CST8207 lectures due to distraction problems: - - Scanning the Log File --------------------- Here are command pipelines that extract information from the system authorization log file `/var/log/auth.log` on who is trying to attack the [Course Linux Server] (may require privileged read permission on the log files). The format of each line in this file is like this: Jan 2 09:51:17 idallen-ubuntu sshd[28008]: Failed password for root from 50.46.204.2 port 33092 ssh2 Each line starts with the date, followed by some text. (Different log files may have different date formats.) I worked through these pipe examples below in class this week. > Each of these commands below is one, long single command line, but to make > the long lines easier to read in this document the long lines have been > split into multiple lines by using a backslash at the end of a line to mean > “continue this with the next line”. You can either type the lines with the > backslashes at the end, as shown below, or else simply type one long line > and omit the trailing backslashes: - Find users with most failed passwords (since the log began): - The userid field is the 9th blank-separated field on each of these lines in `/var/log/auth.log` - We need a numeric sort on the output of `uniq -c` fgrep 'Failed password' /var/log/auth.log \ | awk '{print $9}' | sort | uniq -c | sort -nr | head - Failed passwords only in January: - This log file uses the abbreviation `Jan` for “January”. (Different log files may have different date formats.) - Add a second `fgrep` to further limit the lines to ones that contain the date string `Jan` followed by a blank: fgrep 'Failed password' /var/log/auth.log \ | fgrep 'Jan ' \ | awk '{print $9}' | sort | uniq -c | sort -nr | head - Failed passwords only in February: - This log file uses the abbreviation `Feb` for “February”. - Just change `Jan` to `Feb` in the search string: fgrep 'Failed password' /var/log/auth.log \ | fgrep 'Feb ' \ | awk '{print $9}' | sort | uniq -c | sort -nr | head - Connections refused only in February: - Change `Failed password` to `refused connect` in the search string. - The IP address is the 10th field on each of these lines in `/var/log/auth.log`: Jan 2 02:18:27 idallen-ubuntu sshd[18078]: refused connect from 222.189.239.75 (222.189.239.75) fgrep 'refused connect' /var/log/auth.log \ | fgrep 'Feb ' \ | awk '{print $10}' | sort | uniq -c | sort -nr | head Real Sysadmin Work ================== EC recommends supporting open document format --------------------------------------------- - *All European institutes should be able to use the Open Document Format (ODF) in exchanges with citizens and national administrations,* says Vice-President of the European Commission Maroš Šefčovič, in response to questions by member of the European Parliament Amelia Andersdotter. *There is no lock-in effect whatsoever, and no contradiction with the Commission’s strategy on interoperability.* ![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/ [Unix Shell I/O Redirection (including Pipes)]: 200_redirection.html [Shell Variables]: 320_shell_variables.html [Start-Up Files]: 350_startup_files.html [List of Commands You Should Know]: 900_unix_command_list.html [Video Tutorials on Lynda.com]: 910_lynda_index.html [lynda.com]: http://algonquincollege.com/onlineresources/mobileStudent/lynda.htm [Unix for Mac OS X Users]: http://www.lynda.com/Mac-OS-X-10-6-tutorials/Unix-for-Mac-OS-X-Users/78546-2.html [download Libre Office here]: 050_course_introduction.html#install-libreoffice-or-openoffice-into-windows [The VI (VIM) Text Editor]: 300_vi_text_editor.html [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/