CS35: Lab 7: Working Remotely

Due Wednesday, March 25th at 11:59pm.

Overview

Note: This lab is weighted 25% of a normal lab.

The purpose of this mini-lab is to make sure every CS35 student can operate remotely. Our approach will be to have you remotely edit files that exist in your normal lab directory. You’ll also use ssh to remotely log onto lab machines and do compiling/testing/debugging from there.

Our goal is to get you comfortable using atom, ssh/putty, and scp/winscp to write, compile, and run programs on lab machines remotely from your own machine.

In this lab, you will:

  • Set up ssh/putty to log into CS lab machines remotely.

  • Set up and practice using atom remote edit.

  • Practice compiling and running programs over ssh/putty.

  • Learn to use scp to copy pdf files from lab machine to your local machine.

Note: Once you have everything installed and configured, this lab should not take very long. The main goal of the lab is to make sure you are configured, so you can make progress easily on the next lab.

Part I: Installing and configuring the software you need.

The first step is to download any software you’ll need to run. All of you will need to download atom, and configure it to remotely edit files on your CS department lab machines. Windows users will also need to download a program called PuTTY, which acts like a terminal window, and a program called WinSCP which lets you copy files from your lab machine onto your windows computer.

Download and install the following programs:

  • atom. If you haven’t yet, download the atom text editor.

  • atom remote edit: to use atom to remotely edit files, follow directions from this page: https://www.cs.swarthmore.edu/newhelp/atom-remote-edit.html Once you have these installed, you should be able to use atom to remotely edit your code that lives on a lab machine.

  • Windows users only: putty

  • Windows users only: WinSCP

How do I log in?

Mac/Linux.

Mac users, open up terminal, an application which you should be able to find in Launchpad or from spotlight. Linux users, open up your favorite terminal emulator.

To log into a lab machine remotley, use the following command:

ssh username@lab.cs.swarthmore.edu

You should replace "username" with your CS lab machine user name. Once you enter this command, you will be prompted to enter your password. Note that when you type in your password, no letters will appear!

Once you are logged in via ssh, you can treat your terminal as though you are using a terminal on a CS lab machine.

Windows.

Open putty. In the bar titled "Host Name (or IP address)", enter the following:

username@lab.cs.swarthmore.edu

You should replace "username" with your CS lab machine user name. Then click "Open" at the bottom of the window. Once you enter this command, you will be prompted to enter your password. Note that when you type in your password, no letters will appear!

Once you are logged in via ssh, you can treat your terminal as though you are using a terminal on a CS lab machine.

Part II: Making sure you can operate remotely.

In this part, you will perform three tasks you’ll typically need in CS35: writing code, debugging code, and writing in LaTeX. We’re giving you three short problems to verify you can do each task.

(1) How do I compile/run?

As normal, you should be able to navigate through the terminal to the directeory where you store youre cs35 files (e.g. ~/cs35/). From here, you should be able to clone your git repo for this lab as normal.

Once you have cloned your git repo, confirm that you can compile and run sayHello.cpp using clang++.

clang++ -g --std=c++11 -o sayHello sayHello.cpp

Next, use atom ftp-remote-edit to modify sayHello.cpp. Ask the user to enter a name, and then say hello to that person instead of just saying hello.

Once you’ve made that change to sayHello.cpp, compile and run your program again to make sure it works.

(2) How do I debug?

In your git repo, you should have a file called debugMe.cpp. This program contains a function that takes an integer n from the command line. The program should output the sum of every other number:

$ ./debugMe 5
The sum of every other number up to 5 equals 9
$ ./debugMe 4
The sum of every other number up to 4 equals 6
$ ./debugMe 200
The sum of every other number up to 200 equals 10100

Unfortunately, this program has a bug, and on some inputs the program segfaults!

Try compiling debugMe.cpp and debugging it using gdb and/or valgrind. Because this is just like a normal lab terminal, you can use gdb and valgrind as normal:

valgrind ./debugMe 5

or

gdb debugMe
// Some version info prints out
(gdb) set args 5
(gdb) run

Once you have found the bug, fix the issue using atom ftp-remote-edit, then use your ssh/putty terminal to try to recompile and run.

(3) How do I compile/view pdfs?

In your git repo, you should have a file named WrittenLab.tex. Open this file using atom ftp-remote-edit, and try making a few modifications. Once you are done, from your ssh/putty terminal, run

pdflatex WrittenLab.tex

Assuming there were no errors, this should generate, among other things, a file named WrittenLab.pdf. This is the pdf containing the results, however you can’t view this directly over ssh/putty. You will first have to copy it to your local machine, then open it locally. How you do this differs depending on your system.

Mac/Linux

Open a new terminal window, but do not ssh into lab. You will use another tool called scp ("secure copy") to copy the file from the lab machine to your local machine. For example, if your Swarthmore username is brody (it is not) and your lab07 files live in a directory called cs35, then you could copy with this command:

scp brody@lab.cs.swarthmore.edu:/home/brody/cs35/lab07-brody/WrittenLab.pdf .

The command above copies the file from the lab machine at the path "/home/brody/cs35/lab07-brody/WrittenLab.pdf" to the given directory on your machine. You will want to replace brody with your CS lab username. You might also need to change the path if you cloned your lab somewhere other than ~/cs35/lab07-brody. The "." at the end represents that you are copying the file to the current directory you are in in your terminal.

Now you should be able to navigate to the pdf using finder or spotlight. Make sure that you can open it using your favorite pdf viewer!

Windows

Windows computers don’t have scp; however, WinSCP is essentially the same. You can copy your WrittenLab.pdf over in the same way.

Summary of Requirements

When you have finished, you should have

  • a working sayHello.cpp program that asks the user for their name and says hello.

  • a working debugMe.cpp program that computes the sum of every other positive integer up to the input n.

  • a WrittenLab.tex document with answers to a few simple questions.