User Tools

Site Tools


opus:fall2012:smeas:part1

Part 1

Entries

Entry 1: August 31st, 2012

Today, we talked about revision control, and the variations it has gone through since its induction. We then proceeded to set up our own repositories on Lab 46's servers, using Mercurial. I have previously used Mercurial in Structure and Object Oriented Problem Solving with Joe, and I also use it in his C/C++ course. In his course, however, we use Bitbucket as a hosting service. I already feel proficient in using Mercurial on Linux systems, but using it on a dedicated server is new to me.

Entry 2: September 7th, 2012

Today in class, we finished exploring the UNIX/Linux file system, and moved on into using the VI text editor. I've been using VI personally for about a month now, but I was still amazed at some of the new commands I started to learn. I had thought I was quite proficient in it, but a few of the new commands made me realize that I'm still just a starter to VI. Likewise, I had felt very productive in it before, but with some of the new commands I know that my productivity with it will increase even more. Specifically, using 'o' or 'O' to start inserting on a new line before or after a line, as well as using 'd' to select a line and 'd' a second time to delete that line. I look forward to learning even more tips and tricks to increase my productivity in VI.

Entry 3: September 14th, 2012

Today in class, we started going over data streams and redirecting input and output.

A few of the main things we touched on were:

cat <filename>: Displays the content of a text file in the terminal echo: Returns a string to the terminal $: Indicates that what follows is a variable here strings: Inputs a variable into a command pipes (|): Allows you to use the output of one command as the input to another

We combined a few of these things into the command:

/usr/bin/who | grep $USER

This command returned to us our login sessions for Lab46

Entry 4: September 28th, 2012

Today we began by talking a little bit more about scripting. I feel a little more comfortable about scripting now, after having worked with it a little for my first experiment. The first thing we talked about was that the shabang can point to different directories than /bin/bash. One of the main reasons for this would be if the script was written with a different language, such as perl, Python, or LUA. We then wrote a very basic script, which echoed a string, asked for an input, then echoed another string which contained the input.

Next, we wrote a second bash script. This script first picked a random value, then prompted the user to guess the value. The two numbers were then evaluated in an if statement which determined whether they were equal or not, and then printed a string telling the result.

Keywords

Unix/Linux Keyword 1

Version Control

Definition

Version control refers to managing the changes in a document, source code, or other collection of information. The changes are usually documented by a revision number, timestamp, and who made the change. Revisions can then be compared with or restored to a previous revision. Version control uses a repository, which stores both the current and previous data of the files being version controlled. Version control repositories can either be local only, client-server, or distributed.

Local only repositories are outdated and obsolete. In a local only system, all users must share the same computer system. In a client-server version control system, users share a single repository. While not as outdated or obsolete as a local only repository, it is still not the optimal choice. A distributed revision control system (DRCS) creates a peer-to-peer network, where each user has their own local repository. Changes are then shared between repositories. One of the biggest upsides to a DRCS is that it does not rely on a central node, and therefore is more durable. Two of the most popular DRCS's are Mercurial and Git.

References

Unix Keyword Phase 2

File Compression.

Definition

involves encoding information using fewer bits than the original file. It helps reduce resources usage such as data storage space or transmission capacity. In order to use the data again though you must uncompress the file.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

  • Reference 1
  • Reference 2
  • Reference 3

unix Keyword 1 Phase 2 Phase 2

File Compression

Definition

File compression is the reduction in file size by encoding the file using fewer bits than the original file. This can be done by eliminating redundancies in the file (lossless compression), or by identifying and removing marginally important data (lossy compression).

References

Demonstration

To demonstrate the file compression, I first created a regular ASCII text file. The original filesize was 1.4kb (Containing a glorious rap I wrote about file compression, which was mostly rambling). Then, to demonstrate how compression works, I used the command “gzip -9 compression.txt” to compress the file with the maximum compression. The output of this was a new file titled compression.txt.gz, which now had a size of 729 bytes (approximately 50% compression).

lab46:~/Compression Demonstration$ ls -lh
total 4.0K
-rw-r--r-- 1 smeas lab46 1.4K Sep 28 01:36 compression.txt
lab46:~/Compression Demonstration$ gzip -9 compression.txt
lab46:~/Compression Demonstration$ ls -lh
total 4.0K
-rw-r--r-- 1 smeas lab46 729 Sep 28 01:36 compression.txt.gz
lab46:~/Compression Demonstration$ 

Experiment 1

Question

Is it possible to create a bash script file on my local machine which will automatically connect to Lab46 over SSH and log me in?

Resources

http://askubuntu.com/questions/61963/can-i-create-an-ssh-login-script
According to this question asked on askubuntu.com, it is possible to not only create an SSH login script, but it's possible to set a terminal to automatically connect through SSH when it is opened. While this would be nice, I would much prefer creating a bash script, as I usually always have a terminal open and would find it much easier to type ~/filename.sh

Also, this website handles a passwordless SSH connection. This would not work, because Lab 46 obviously requires a password.

http://unix.stackexchange.com/questions/31071/shell-script-for-logging-into-a-ssh-server
According to this question thread on stackexchange.com, the expect command can be used to do exactly what I'm attempting to do. By creating a script file to first send the SSH command, then wait for a password prompt, and when the prompt is received send the password to the server.

Hypothesis

Based on what I've read in regards to my question, I'm very confident that a bash script file can easily be written to automatically connect to Lab 46. It seems that other people have had success using the expect command in a script to do so.

Experiment

To test my hypothesis, I will create a two .sh bash script files. The first file (461.sh) will be created solely using my preexisting knowledge of scripting, in an attempt to create the script in a way which I feel should logically work. Based on what I know, I feel that I could create a script file with the following code that will work (substituting the variable “mypassword” for my actual password. Ain't nobody stealing my logins!)

#!/bin/bash
#
# 461.sh - A script file to automatically connect to Lab 46
#
`ssh smeas@lab46.corning-cc.edu`
sleep 3
`mypassword`

In the second step of my experiment, I will use what I read from the http://unix.stackexchange.com/questions/31071/shell-script-for-logging-into-a-ssh-server question thread. I will first have to use apt-get to download the expect package. Then, basing my script completely off of the first answer in the question thread, I will create a second script file (462.sh). This script file will contain the following (again using “mypassword” instead of my actual password, to protect my sensitive materials!“)

#!/usr/bin/expect
#
# 462.sh - A script file to automatically connect to Lab 46
#

spawn ssh smeas@lab46.corning-cc.edu
expect "password"
send "mypassword\r"
interact

Data



Based on my basic knowledge of scripting, this would first send the ssh command, then wait 3 seconds (which I figured to be an appropriate wait time to receive the password prompt), then send my password. I used the command `chmod +x 46.sh` to allow me to execute the script. Unfortunately, this script failed. It connected to Lab 46 and received the password prompt, but did not enter the password. I attempted to raise the sleep timer to 10, just in case it needed some more time, but it also still stalled out at the password prompt. I feel like my logic was correct, but my syntax was not.



Again, after saving this file as 46.sh, I first ran a `chmod +x 46.sh`. I then executed the script, and as I expected, it worked flawless. In a matter of seconds, I was sitting on the home screen of Lab 46.

Analysis

Based on the data collected, my hypothesis was correct. It was possible to create an ssh connection/login script for Lab 46. There was more going on than I originally though, because I had to download a package which allowed me to use some more commands in a bash script.

One shortcoming of my experiment is that there may have been another way to do it. If so, however, I don't think it would have been any more optimized than my script was. My script involved downloading one very small package, and writing a four line script file. I feel there wouldn't be a more succinct way to achieve this.

Conclusions

Based on the experiment I performed and data I collected, I can ascertain that scripting is a very powerful tool to have in my arsenal. While the amount of time saved between logging in normally, and logging in with my script (which requires only five keystrokes) may only be a few seconds, but I feel like those few seconds will add up over time and make the initial investment more than worth it.

My biggest discovery in this experiment is that the bash scripting language is expandable. It is not limited to the commands available initially. Downloading the “expect” package gave me access to a number of other commands to increase the versatility of my bash script.

opus/fall2012/smeas/part1.txt · Last modified: 2012/09/28 16:35 by smeas