CS114: Homework 2
Do all of the problems below on one of the CSUG Linux machines, i.e. csug01 through csug06.csuglab.cornell.edu. Run the submission script for problem 1. Turn in your answers (hardcopy) to problems 2 and 3
with your full name and netID, in class or in my mailbox (657 Rhodes) by 5 p.m. on the due date given
on the main course page.
Problem 1
- Use chsh to change your login shell to bash.
- Create customizable shell initialization files for bash: copy /usr/share/skel/bashrc:Linux.2 to your home directory as .bashrc:x.y where x is the name of your operating system and y is the version of your OS. (Use the uname command.) Copy /usr/share/skel/profile:Linux.2 to .profile.x.y similarly.
- Edit the customizable .bashrc file to set the following environment variables as you see fit: EDITOR, PAGER, HISTSIZE. Also set three new variables whose names start with 'my' to values of your choice. (You make up these variable names and values.)
- If it does not already exist, create a file ~/.aliases. Add at least three aliases to
the file.
- Include a line in your .bashrc:x.y file to ''source'' the .aliases file.
- Ensure the rc files and also .aliases are readable and writable by you only and
not executable.
- In your .profile:x.y file, set your umask to so that,
by default, you have no access restrictions, members of the group cannot write files, and all
others have no access.
To submit this assignment, run the script ~wes28/bin/submit-2. Be sure you have logged out and logged back in before running the submission script, and be sure that you are logged in using the new shell when you run the script. Make ONE submission ONLY.
NOTE: When you are finished with the submission, you are free to change your shell, variables, etc. to whatever you would like.
Problem 2
Create one-line commands using | that do the following:
- Appends a list of the currently running processes (in any format) to the end of the file processes. This can include background and stopped processes, and not just processes that you own.
- Prints to the file count the number of unique users (and only the number) currently logged in. The commands who, cut and sort -u may be helpful.
- Prints the process ID (and only the process ID) of any bash or -bash (indicating bash run as a login shell) process running on the machine. Be careful to not include processes that just contain the
string ''bash'' on the command line (such as the commands you write to search for processes named ''bash''). The -e option to egrep may be helpful.
Problem 3
- For our purposes, a URL is any string that starts with "http://", is followed by a hostname,
and then, optionally, ends with a path. A hostname is just a
non-empty string containing no whitespace (i.e., spaces and tabs) and no "/". A path is any
string of non-whitespace characters starting with a "/". Examples of URLs include
- http://www.google.com
- http://www.cs.cornell.edu/
- http://www.cs.cornell.edu/courses/cs114/2005fa
Write a sed command that extracts the hostname from a URL. For example, for the URLs above
the command should print
- www.google.com
- www.cs.cornell.edu
- www.cs.cornell.edu
You may assume the input to sed consists of a single line containing only the URL (as if it were
output from echo http://...).
- Look at the man page for elinks, a text-based web browser.
Write a one-line command using elinks
-source URL , grep and sed that prints only the text between the
<title> and </title> tags of the
webpage referred to by URL.
You may assume that both tags occur on the same line in the webpage
source and that each tag occurs only once. The command should output at most one line.