Goals for this lab |
|
Summary |
Most (if not all) of the work we do this semester will be in a Linux command environment. While Linux has a graphical user interface much like Windows does (where you can use a mouse to click on buttons and move windows around), we'll be dealing mostly with its command line interface. The idea of a command line interface is simple - we type commands, as text, and Linux evaluates them (perhaps by running a program) and tells us the results. However, as we'll see, the command line is very powerful. In the lab instructions, you'll see several recurring visuals:
These represent things you should type at the command line, or examples of command line techniques. The items after the > are the things you type; what
comes before the represents the prompt. Yours may look different.
Hopefully, these common elements will help you complete the labs quickly, and understand them well. |
Answering Questions |
Some labs will involve creating and running a Perl program to solve a problem, but
many also involve answering some written questions. We'll mix these in with the lab in
convenient spots. Write down the answers using the editor of your choice (such as
Nano, which we'll talk about soon). When you are done with the lab, you'll be asked to
submit these answers along with any code you write. Make sure your name is in any file
- text or code - that you create. Here's an example of what your answers should look
like:Buck Rogers Lab 1 April 1, 2009 ------------- 1. Answer to first question goes here 2. Answer to second question ... This file should be called lab1.txt. |
Using Linux |
Okay, enough talk. Time to get started using Linux!
Do This:
You're now connected to Do This:
Type the commands in the following command line block. The output you should see is also shown. jpr@sulu (~) > mkdir i211 jpr@sulu (~) > cd i211 jpr@sulu (~/i211) > mkdir lab1 jpr@sulu (~/i211) > cd jpr@sulu (~) > ls -R i211/ ./i211: lab1/ ./i211/lab1: jpr@sulu (~) > Now your account is set up so you can keep your work this semester organized. Let's practice with some advanced shell commands. jpr@sulu (~) ls -R > listing jpr@sulu (~) > The > is a redirection operator; it takes the output of any command and
puts it in a file instead of printing it on the screen. < lets a command take its
input from a file, and Take a look at the file you just created... jpr@sulu (~) > cat listing i211/ ./i211: lab1/ ./i211/lab1: jpr@sulu (~) > This file is in the wrong place; let's move it to the i211/lab1 directory. To do this, use the mv command...jpr@sulu (~) > mv listing i211/lab1 jpr@sulu (~) > ls -l i211/lab1 total 8 -rw------- 1 jpr jpr 40 Aug 29 18:25 listing jpr@sulu (~) > Exercise 1:
Using a Linux text editor such as nano, edit the listing file you just moved into lab1 so that it has a line of text at the top (such as "Here is my directory structure"). Save the resulting file. You can launch nano by nano listing .
Now, use Nano to create a file in your Exercise 2:
Now, let's experiment with a few more commands. Exercise 3:
Choose three more Linux commands. Describe them and give examples of their use; type the answers in your lab1.txt file.
|
Your first Perl program! |
Time to write your first Perl program! Use nano hello.pl to create a file called hello.pl in your lab1 directory. Then type the following code in it:#!/usr/bin/perl -w print "Hello, World!\n"; Now try running your brand-new program: jpr@sulu (i211/lab1) > perl hello.pl Hello, World! jpr@sulu (i211/lab1) > If your program prints Hello, world! then congratulations! You've written your first Perl program. Now let's improve it so that it prints out an HTML page. To do this, we can use the handy module CGI.pm . Later, we'll talk more about how this works, but for now, use Nano to change your hello.pl file so that it looks like this:#!/usr/bin/perl -w use CGI qw( :standard ); use strict; print header(), start_html( 'Hello!' ); print "Hello, World!"; print end_html(); Okay, that's a lot to understand all at once, but don't worry. We'll discuss it in detail later. For now, just run your new program and watch how it prints out all the HTML you need for a web page, automatically. Now, let's put the script in the right place to be viewed by a browser. jpr@sulu (i211/lab1) > cp hello.pl /var/www/cgi-bin/jpr/hello.cgi jpr@sulu (i211/lab1) > chmod 755 /var/www/cgi-bin/jpr/hello.cgi jpr@sulu (i211/lab1) > Those cryptic commands accomplished two things:
http://sulu.informatics.indiana.edu/cgi-bin/jpr/hello.cgi (where jpr should be replaced by your username) to see if your script works. If it does, then you are done! Time to submit.
|
Turn in your assignment |
This semester, we'll be using Oncourse to submit assignments. Since you need to use a web browser to access Oncourse, you'll need to download your files onto your desktop computer before submitting. To do this, we'll first create a "tarball" of your lab directory, then download that and submit it to Oncourse.jpr@sulu (i211/lab1) > cd .. jpr@sulu (i211) > tar cz lab1 > lab1.tar.gz jpr@sulu (i211) > Now the directory lab1 , together with all the files that were in it, is contained in the lab1.tar.gz file. Use the "File Transfer" menu option to download this file to your desktop, and submit it to the "Lab 1" assignment in the assignments tab of Oncourse.Okay, that's it! Go home and have a good weekend. |