$25
The goals of this assignment are as follows.
• Find the main CS lab at NPB 2.118
• Log in to a machine with your user id
• Utilize some essential Unix commands
• Utilize vi (actually vim) and get familiar with the vi cheat sheet
• Create and run a simple shell script
This assignment refers to a setup page which can be found on Blackboard under the Miscellaneous section. In particular, you should get visit the vi cheat sheet, Unix cheat sheet, vim tutor, and ssh download if you are planning on using Windows to connect to the department machines.
Steps
1. Log in to Linux
(a) Go to the CS Department lab at NPB 2.118. If working remotely, see how to log in remotely on the setup page and skip to step 1(e).
(b) There are two types of workstations in the lab:
• Dell Thin Client - (left side of lab) These access the VDI (like the machines in the classrooms). To use them, see the instructions on the setup page.
• Linux Workstations - (right side of lab) These run Ubuntu 14.04 and are ideal for the work you will do in this course.
(d) Open a terminal window. From the desktop menu, use Applications>Accessories>Terminal or Applications>Accessories>LXTerminal
(e) Since you are using a temporary password, change your password using the passwd command. (Note that the “$” is being used to indicate that the Linux shell is prompting you for input). The actual prompt may look different (e.g., your user ID). In the terminal window, type (without the “$”):
$ passwd
Notes: If you are logging in remotely, do the following instead:
• If using Linux:
– Start a terminal window and enter the following command:
(where abc123 is your abc123 and ii is one of 01 through 06)
• If using Windows:
– You should install ssh (see the setup page).
– You can transfer files with an sftp client (not ftp)
– For both, you will specify to connect (where abc123 is your abc123 and ii is one of 01 through 06)
– In the future, consider using a virtual machine (e.g., VirtualBox), dual boot, or Cygwin.
2. Create a directory for this course and copy important course files to it. (You may want to check the Unix Cheat Sheet for help here).
(a) After logging in, check your current directory using the print working directory command:
$ pwd
(b) See what files are in your current directory:
$ ls -al
(This will show all files and give long details on them. You will notice “hidden” files beginning with a “.”.)
(c) Create a directory for this course:
$ mkdir ~/courses/cs3423 -p (d) Change to your cs3423 directory:
$ cd ~/courses/cs3423
(You should verify that you are in the directory with the pwd command.) (e) Copy the course materials to your directory:
$ cp /usr/local/courses/rslavin/cs3423/* . -r
(You should verify that the material was copied by using the ls command.)
3. Use the vi editor to create a simple shell script.
(a) Study the vi Cheat Sheet from the setup page. (b) (optional) Try the vi tutorial:
$ mkdir ~/tmp 2> /dev/null; cd ~/tmp $ vimtutor
(follow the instructions)
(c) If you haven’t already in a prior course, create a .vimrc file to set up defaults in vim for indention and line numbers.
$ vi ~/.vimrc
:set
ai sw=4
:set
number
:set
expandtab
:set
softtabstop=4
:set
smartindent
(d) Create your first script for this class using vi. Note: Be careful to type each character, including spaces, exactly as it appears below. Copying and pasting will not preserve spaces correctly.
i. $ cd ~/courses/cs3423
ii. $ mkdir assignments
iii. $ cd assignments iv. $ vi cs3423a0
v. Enter the following code exactly as it appears.
#!/bin/bash
if [ $# -ne 2 ]; then
echo "usage: $0 <firstName> <lastName>" exit 1
fi
echo "My name is $1 $2"
echo "I am running this script from `pwd`" echo "My username is `whoami`" echo "I am logged in to `hostname`"
4. Exit your text editor and make your script executable:
$ chmod u+x ./cs3423a0
5. Execute your script and verify the output. In the command below, replace myFirstName and myLastName with your actual name.
$ ./cs3423a0 myFirstName myLastName
It should print the following:
My name is myFirstName myLastName
I am running this script from /home/myUsername/courses/cs3423/assignments
My username is myUsername
I am logged in to myHostName
6. You now need to save the output of your script by redirecting the output to a0Out.txt.
$ ./cs3423a0 myFirstName myLastName > a0Out.txt
$ zip -r abc123.zip cs3423a0 a0Out.txt