% CST8207 Week 05 Notes – redirection, variables, start-up files % Ian! D. Allen - - [www.idallen.com] % Winter 2014 - January to April 2014 - Updated Wed Feb 5 19:18:56 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** - [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 Wednesday, February 12 in your lecture. - See the [Week 04 Notes HTML] for details about the test and the quiz. 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 #02 HTML] – simple file system commands on the CLS - [Assignment #04 HTML] – simple commands, copy, GLOB and redirection - Really do **Read All The Words**. You don’t get a second chance to get it right. Lab work this week ------------------ The worksheets are available in four formats: Open Office, 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. - [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, alias, sum - [Worksheet #05 HTML] – I/O Redirection and Pipes - I/O redirection and 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. 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. - Class Quiz - Finishing redirection and pipes this week. - 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 - No man page for `bash` built-in commands `cd`, `alias`, `history`, etc. - use the `help` built-in command: `help alias` 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). I worked these examples in class this week: - 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`: Jan 2 09:51:17 idallen-ubuntu sshd[28008]: Failed password for root from 50.46.204.2 port 33092 ssh2 fgrep 'Failed password' /var/log/auth.log \ | awk '{print $9}' | sort | uniq -c | sort -r | head - Failed passwords only in January: - Add a second `fgrep` to further limit the lines to ones that contain the string `Jan` followed by a blank: fgrep 'Failed password' /var/log/auth.log \ | fgrep 'Jan ' \ | awk '{print $9}' | sort | uniq -c | sort -r | head - Failed passwords only in 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 -r | head - Connections refused only in February: - Just change `Failed password` to `refused connect` in the search string. - The IP address is also the 9th 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 $9}' | sort | uniq -c | sort -r | 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]: 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 [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/