% Week 13 Notes for CST8207 - Winter 2012 % Ian! D. Allen - idallen@idallen.ca - www.idallen.com % Winter 2012 - January to April 2012 Tests and Exams =============== * The Final Exam date is posted on the [Course Home Page]. * Tests are short answer and multiple choice. * For full mark credit, read the [Test Instructions] for important directions on how to enter your answers on the mark-sense forms. * Each test covers material on the preceding assignments and Weekly Notes, with emphasis on material in the assignments. The Final Exam includes some material from the Midterm tests. * Basic calculators are permitted for all tests and exams but will not be needed. (No phones or PDA devices.) * Final Exam: Monday April 23 11h30 (11:30am to 2pm) - CA105(A,B,C). A practice question set will be available in Week 14. Lecture Notes for This Week =========================== From the Class Notes link on the Course Home Page ------------------------------------------------- * [Test Instructions](000_test_instructions.html) - Important directions on how to enter your answers on the mark-sense forms. * [This is Your Brain on the Internet](005_this_is_your_brain.txt) * [Frequently Asked Questions](007_freqently_asked_questions.html) * [How to report Problems](008_how_to_report_problems.txt) * [Installing VMware Tools](010_vmware_tools.html) * [Why Learn the Unix Shells?](100_why_shell.txt) * [Command Line vs. GUI: Power Users need more than GUI](110_command_line_vs_gui.txt) * [The Unix/Linux Shell](120_shell_basics.html) * [Searching for items in the Unix manual pages (RTFM)](130_man_page_RTFM.txt) * [Options and Arguments on Unix Command Lines](140_arguments_and_options.txt) * [Unix/Linux Pathnames (absolute, relative, dot, dot dot)](150_pathnames.txt) * [Hard links and Unix file system nodes (inodes)](200_links_and_inodes.html) * [Unix/Linux File System - (correct explanation)](210_file_system.txt) * [Directories: ROOT, /root, HOME, /home, and current](220_home_and_HOME.txt) * [Searching for and finding files by name, size, etc.](250_finding_files.txt) * [GLOB patterns (wildcard pathname matching)](260_glob_patterns.txt) * [Unix Shell I/O Redirection (including Pipes)](270_redirection.txt) * [Unix/Linux Shell Command Line Quoting Mechanisms](280_quotes.txt) * [The VI (VIM) Text Editor](300_vi_text_editor.html) * [Unix Modes and Permissions](400_permissions.txt) * [Umask and Permissions](410_umask.txt) * [Symbolic Links - Soft Links - Symlinks](420_symbolic_links.txt) * [Shell Variables - Basics (non-scripting)](430_shell_variables.txt) * [Shell search PATH - finding and running commands](450_search_path.txt) * [Setting up Startup Files: .bash_profile and .bashrc](470_startup_files.txt) * [Linux Disks and Partitions](500_Linux-Partitions.pdf) * [Create a New VMware Virtual Hard Disk](510_create_vmware_disk.pdf) * [Unix/Linux File Systems - mkfs, mount, swap](520_file_systems.html) * [Users and Groups - /etc/passwd and /etc/group](480_users_and_groups.html) * [Unix/Linux Boot Process, GRUB, and run levels](610_booting_and_grub.html) * [Unix/Linux Command List (cumulative)](900_unix_command_list.txt) ![Read All The Words](data/read_all_the_words.jpg "Read All The Words")\ ### Assignments and Labs ### * See your [Blackboard] ToDo list for all assignment due dates * Done [Lab #09] - Disks, Partitions, and File Systems - Part 2 of 2 * Do [Lab #10] - Boot Process and GRUB * To get your Lab marks, complete your Self-Mark surveys on Blackboard. From the Classroom Whiteboard/Chalkboard ---------------------------------------- ![How Many Lines](data/kf_link_redirect.jpg "How Many Lines")\ * How Linux is Built: * Your in-class notes go here. - If you're not actively taking notes in class, why are you here? * Send me video from the Rap. My wife wants to see me. - Hey! I've **still** not received any video. Anyone out there? * Dates for tests: - Final Exam on Monday April 23. Do the practice tests first. The Final Exam includes all material. * The Internet Is Ruining Your Brain [INFOGRAPHIC] * Learning the Material - how do you do it? - searching the course notes vs. searching the entire Internet * The Boot Proces and GRUB Bootloader - [Unix/Linux Boot Process, GRUB, and run levels](610_booting_and_grub.html) Choosing a File System Type --------------------------- Your system install created "journalling" file systems on your virtual disk, using the "-t ext3" option to mkfs. Another way to request this kind of file system is to use the "-j" (Journalling) option to the original "mke2fs" command. This type of Linux journalling file system is usually called "ext3", and some distributions have a small shell script named "mke3fs" that simply calls mke2fs with the "-t ext3" or "-j" option. Journalling file systems are more resistant to corruption due to sudden power loss, allowing the system to come back up more quickly by avoiding a long file system check at boot time. (This does *NOT* give you permission to power off a running Linux system! Always shut down cleanly.) * Q: What is the advantage of a journalling file system? System Logging - syslog and /var/log/ ------------------------------------- Logging of system messages is handled by a **syslog** process, a process that listens for connections and writes messages to log files. System logging is configured via files in /etc such as /etc/syslog.conf, /etc/rsyslog.conf, etc. The syslog process is started by system start-up scripts such as klogd, sysklogd, rsyslogd, etc. The main daemon name is usually something like "syslogd" or "rsyslogd" or "klogd". $ ps laxww | grep syslog $ ps laxww | grep klogd Logs are usually stored under directory /var/log/; but, the configuration file may have syslog put them anywhere. * Unix/Linux System logging - figuring out where things go wrong: - logging needs a system log daemon and kernel log daemon running: - daemon is started via a script such as /etc/init.d/syslog - syslog uses a config file, e.g. /etc/syslog.conf, /etc/rsyslog.conf - the config file assigns types of logging to various file names - usual syslog log file directory: /var/log/* - know how to find out where the logs are kept! * Kernel messages: - "dmesg" shows the kernel ring buffer (limited size) - works without any log daemons running - kernel messages may also be saved under /var/log/ somewhere * Q: What file controls and configures system logging? * Q: Under what directory are most log files usually stored? * Q: What command shows the kernel ring buffer, even if logging isn't enabled? Unix/Linux Shell Job Control and Background Processes ----------------------------------------------------- Normally when you run a command, the shell waits until the command is finished before it prompts you for the next command. If you want to run a command "in the background", without waiting for it to finish, and have the shell prompt you immediately, end the command with an ampersand **`&`**, e.g. $ sleep 60 & [1] 18920 $ If you have already typed a command and forgot to use the **`&`**, you can put a foreground process into the background by typing **`^Z`** (CTRL-Z) to suspend the process, followed by **bg** to put it into the background: $ sleep 60 ^Z [1]+ Stopped sleep 60 $ bg [1]+ sleep 60 & You can bring a background job into the foreground using **fg**: $ jobs [1]+ Running sleep 60 $ fg sleep 60 You can list the jobs of the *current* shell using the **jobs** command. $ jobs [1]+ Running sleep 60 You can send signals, including termination signals, to jobs of the current shell: $ kill %1 [1]+ Terminated sleep 60 Process listing and control --------------------------- Programs runs as individual **processes**. Each process has a numeric *process ID* or **PID**. A process usually runs with the userid and group permissions of the person who started it. Some privileged **setuid** programs can run with the userid and/or group of the *file* containing the program. You can usually see the process IDs of all user processes, but you can only terminate or pause your own processes. The "ps" command on Linux is a mix of the BSD "ps" command and the incompatible SystemV UNIX "ps" command. From "man ps": This version of ps accepts several kinds of options: 1 UNIX options, which may be grouped and must be preceded by a dash. 2 BSD options, which may be grouped and must not be used with a dash. 3 GNU long options, which are preceded by two dashes. $ ps # BSD: some of your processes (in current window) $ ps x # BSD: all of your processes $ ps xl # BSD: all your processes, long format $ ps xlww # BSD: all your processes, long format, full wide listing $ ps ax # BSD: all processes $ ps laxww # BSD: all processes, long format, full wide listing $ ps f # BSD: ascii art hierarchical display (forest) $ ps -e # UNIX: all processes $ ps -elww # UNIX: all processes, long format, full wide listing $ pstree # process tree; similar to "ps axf" $ kill # send (TERMinate) signal to a process ID or job number $ killall # send (TERMinate) signal to a process with a given name $ jobs # show child processes of current shell * Q: how do you see all your processes? * Q: how do you see all processes for all users? Scheduled Execution - cron and crontab -------------------------------------- Unix/Linux has a program named **cron** that runs other programs at scheduled times, e.g. run a backup program every day at midnight. The *cron* daemon examines and runs crontab entries once every minute. (The **cron** daemon can't run anything more often than once a minute.) There is a system **cron** configuration file /etc/crontab that can run commands as any userid (usually as root). Most systems also allow individual users to have private crontab files for commands they want to run as themselves. You simply use an editor to edit the system /etc/crontab file. Users must use the **`crontab`** command to manage their personal cron files. * `man crontab - the crontab command for managing individual user crontabs` * `man 5 crontab - the format of the crontab files (personal and system)` # example line from a personal crontab file: 34 12 * * * echo "It's 12:34 and time to eat lunch" | write alleni The five time and date fields at the start of crontab lines are (from `man 5 crontab`): crontab field allowed values ------------- -------------- minute 0-59 hour 0-23 day of month 1-31 month 1-12 (or names, see below) day of week 0-7 (0 or 7 is Sun, or use names) * See `man 5 crontab` for both personal and system crontab file examples Pre-scripting Shell Topics -------------------------- * [Shell Variables - Basics (non-scripting)](430_shell_variables.txt) * [Shell search PATH - finding and running commands](450_search_path.txt) * [Setting up Startup Files: .bash_profile and .bashrc](470_startup_files.txt) [Test Instructions]: 000_test_instructions.html [000_README.txt]: 000_README.txt [000_Licensing.txt]: 000_Licensing.txt -- | 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](http://johnmacfarlane.net/pandoc/) format