Wednesday, October 21, 2009

Forwarding X Through Several Hosts When Configurtion Prevents It

I have computer A at my home, and at school there is computer C, which I want to run X applications and forward to my computer A. Except, Computer C is not accessible from outside the school's network. To get to Computer C, I have to first ssh to Computer B, then ssh to Computer C. Except that Computer B prevents forwarding X from C to B to A. Here is a workaround I found.

First set up a tunnel

ssh -L5091:machine_C:22 username@machine_B

Then ssh by:

ssh -Xp 5091 username@localhost

Test with xclock.

Sunday, September 13, 2009

UVA & Public Computers

I have attended the University of Virginia for a while now, and have grown to cherish their public computing labs. However, as of Spring 2009, we were all notified about the impending retirement of the public computing labs. To say that this created an uproar would be an understatement. A poll was created to show support against the verdict. After talking to several students thereafter, a number had not voted in the poll because they thought it was a joke, "UVA isn't that foolish." As the saying goes, the young are naive.

This decision, coming "out of the blue" so to speak is further proof that student bodies are meaningless entities. The student councils were consulted on the manner, but they had no say. The decision was made by those that make the real decisions. I have served on governing boards before, and it is their sole point is to argue about non relevant issues. They have no authority where it matters. Student governing bodies do not address anything of serious interest to the students. This is why elected positions go unchallenged or even vacant. As far as I could tell, their only purpose (besides arguing) was to ticket expensive "leadership retreats" and wind up partying for a weekend (on my tax dollars most likely). UVA is no exception to this rule.

The decision can be read here: http://www.virginia.edu/uvatoday/newsRelease.php?id=7938 and http://itc.virginia.edu/org/reports/labstransition.html . Initially, it was done because UVA could "better serve its student body." Or something to that effect. Statistics had been gathered across UVA computers. It was determined that the computers were overwhelmingly used for web browsing, pdf viewing, and Microsoft word. I was under the impression that UVA was forbidden to spy on any student, though this does not apply to usage statistics (how did they collect those? Under what circumstances? How long? Over what period?) But I am digressing, that is an entirely different topic altogether. The point is, the statistics were never elaborated upon. They simply were given as evidence, and I had a few issues to pick with them. 99% of entering students owning a computer was believable, and I do not argue that number. But I do argue with the statement that "95%...[of]...students were running commodity or free programs..." or programs available on most personal computers. It is possible that, that number is correct. However where I argue with that number is "which area?" For example, is that the entire school in entirety? Does that include the law school? The college of liberal arts? Then I am surprised the numbers aren't higher. Of course those schools would use Internet Explorer, Adobe, Word, and the like heavily. Or was it just the Engineering School?

If the aforementioned statistics were just the E-School, then that number is bogus. Yes, many times I enter the lab and have only Firefox open with a chat window plus a few tabs for my courses and maybe some topic I am reviewing. Yes, that does happen. But many times, I also have MATLAB running, or MathCAD, or PSpice, or AutoCAD, or a secureCRT connection, or accessing my UVA home directory, or eclipse, or emacs, or occasionally some obscure software that only one class in the whole university uses for pedagogical reasons.

UVA computers also provide convenient access to different journals (such as IEEE), book sites (Safari is a case in point), and numerous other subscription services. Why? Because UVA has a site license for them. It is far more convenient to log on to a UVA public computer, with your computing ID, using the same version of Firefox / Internet Explorer across the whole University, than it is to use your personal computer with godknowswhat operating system and what browser version (heaven forbid, a Safari browser). It is also for practical purposes, we are granted a site wide license via IP addresses. I don't know how this would work for mobile laptop computers, which will likely be NAT'ed. Maybe it will work, maybe it won't. Hopefully they have bothered to look into this. If not, future students will find out.

To further rub salt into the wound, this decision came shortly after UVA decided to outsource its helpdesk to some company in Texas, and lay off all the students employed in the helpdesk. A number of whom were good friends of mine. Yay! Am I bitter? Oh no, don't be silly. Who could be bitter about that. I personally love calling a phone number to some distant help center, probably with an employee who can barely speak English (that is, if I can get to speak to a human being, for all I know they are using a computerized system). And what was the added benefit of outsourcing? For the same price you can now have 24/7 service! Wow! That is amazing! We used to have service till about 11 o'clock. And it was personal and effective. But screw that! We now have service at 3 AM!!! Even during finals most people seldom stay up to 3 AM.

UVA's solution to the problem is profound. Whether they mandate it or not, all students will have to purchase a notebook computer. I, for one, do not like dragging around a full sized notebook all over the place. I use a netbook computer for the convenience (though I am still a big fan of the computing lounges). My netbook computer does run MATLAB under Linux, but it isn't the fastest. The UVA Public Computers are faster by a long shot. Additionally, I don't like installing all the crap that is on the UVA Public Computers on my personal computer. I don't want to deal with the administrative overhead of installing and maintaining MATLAB, MathCAD, autoCAD, PSpice, and all their torturous license server issues (any UVA student can attest to the difficulty of starting a UVA copy of MATLAB on their home computer).

And don't get me started about software version mismatches. This will be a living hell for the CS department. Different versions of Java, eclipse, "well it compiled on my computer just fine!" I ALWAYS use the UVA Public Computers for my final test before I submit ANY code. Period. Why? Because it is a standard! A template that faculty, teaching assistants, and students can compare against.

Even when I bring my netbook computer to the study lounge, I still use a stacks computer! Why? Because it has specialty software and a lot of extra RAM, CPU power, and a larger, crisper screen! I do different tasks on each box.

Printing, another massive issue. I am always printing essays, lecture notes, schematics, time cards, and who knows what else. Setting up a printer can be a massive headache.

And what happens when my notebook dies? Well, if I am in the computing lounge and one of the standard public computers fails, I simply switch to another computer. Guess what. It works. And since I save everything to my home directory, it is as if nothing happens. It is not uncommon for student computers to die, the first three weeks of this semester two close friends have had their computers die.

Now I ask a rhetorical question. Do employers require employees to purchase their own computers? Most certainly not. And do they mandate what software must be installed on the employee's personal computer? Of course not. UVA is requiring all students to buy computers. These computers are no longer personal computers. They are UVA Computers. They will have UVA software, UVA site licenses, UVA approved operating systems, UVA approved versions of every software, and to ease helpdesk requests, they will likely require a typical installation on all boxes. Any System Administrator will tell you the near impossibility of installing software on a heterogeneous collection of computers numbering in the thousands. It is far easier to install it on a homogeneous collection of computers.

I wish UVA would not lie to us. This will not improve service. It will not help students. It will make matters more difficult. It will add a further expensive bar to entering students. Yes, UVA claims their financial aid services will help disadvantage students. But how many people have filled out those forms? Do you have any idea how complicated they are to most people? And many times the results seem entirely arbitrary, or easily exploited by those in the know. Yech. UVA should come out and say they are doing this to handle budget cuts, stop lying to us about “improvements.”

-SynFin

Monday, August 24, 2009

The Smooth Iron

Iron Man, directed by Jon Favreau, left me with a simple thought. It wasn’t the fact that Iron Man was rather long (indeed, it exceeded two hours). No, it was the fact that Iron Man was so smooth.

Iron Man revolves about a character named Tony Stark. Stark is a genius inventor who produces advanced weapon systems for the army. His success in the field made him fabulously wealthy and head of Stark Enterprises. Think of Stark as a blend of Dexter from Dexter’s Laboratory and Bruce Wayne of Batman.

Stark builds a robotic suit that enhances his strength, reaction speed, resistance to damage, and enables flight. But what stood out about the suit was how smooth it was. There wasn’t a single rough edge or “point” across the whole suit. Which brings me to the plot.

Early in the movie, I get the impression that Stark is portraying a pro defense department, “The one who has the biggest stick wins...so make sure America has the biggest.” Then due to a plot twist it looks as if Stark converts to an anti defense department stance. But as we watch, we realize that this also isn’t the case (or at least, it is never explored in the movie.) Instead, Stark builds the “smooth machine” and flies out to Afghanistan to stop terrorists from using weapons he made. Ah! So he is going to set things right, kill the bad guys, make central Asia safe for democracy within all the “stan” countries.

That seemed like a simple enough story. Sadly, that also didn’t go very far. Not too long from then, the biggest, baddest terrorist group in the region is destroyed. Not by Stark, oh no, but by one of the chairmen of Stark Industries. Apparently that chairman was selling weapons to different vendors “under the table” (including those terrorists).

Well, the rest of the story was sadly predictable (less than thirty minutes). The big bad chairman builds his own robotic suit and makes his move. I don’t know exactly what the big bad chairman’s move exactly was at this time. After writing “big bad chairman” two times I must say it was cumbersome, so let’s abbreviate his name to “BBC.” It didn’t make a lot of sense why the BBC (ah, that’s better) was trying to kill Stark. It also didn’t make any sense what he was doing with his manufacturing company. Was he going to make several of these super robots and conquer the world? Was he going to sell them to different groups?

Anyhow, Stark’s favorite girlfriend leads a bunch of special agents to arrest the BBC. The BBC jumps into his suit, wipes out the agents, and proceeds to chase the favorite girlfriend around town. What makes it even sadder, is the BBC never even abducted her. Hell, there wasn’t even a brief hostage situation. Instead, she gets to observe the battle between Stark and the BBC.

Starting out the fight, Stark’s suit was low on power and, predictably, the BBC kicks his ass. The whole fight was depressing. What Stark winds up doing to defeat the BBC, is have his girlfriend overload some reactor which blasts the bad guy away. Wahoo.

As with the man’s suit, the problem with the movie, was it was too smooth. In fact, both were entirely devoid of a point.

Wednesday, August 12, 2009

Check Your Cables

Not too long ago, I purchased an older computer to serve as a file server or test box (pending on my mood). Booting up with a Linux distribution (I think it was Fedora) it reported errors with the hard drive. A casual glance made it seem that a new hard drive was in order. I was busy at the time and let it be.

Fast forward to this evening and I came back to the computer and played around with the drives. At first I thought I had forgotten everything about IDE drivers, master/slave/select options, and the master and slave position of the ribbon. Routinely the box would refuse to boot and its behavior was erratic.

At one point, enabling power to the CD-ROM drive but removing the IDE cable allowed the CD-ROM to turn on. Once I connected the IDE cable, it failed to turn on! Further investigation, involving swapping cables and playing with the BIOS, eventually led me to use only one IDE cable for the CD-ROM and hard drive that was supposedly broken. With the extra ribbon that appeared broken, I started to remove it, only to realize that it was loose!

The ribbon was well sealed behind other ribbons connecting to the board, and I couldn't tell from looking that it was unseated. But sure enough, by feel the ribbon was loose.

The computer booted up fine after some minor BIOS changes (the hard drive and CD-ROM are on the same ribbon, which isn't good but I'll fix that later). The machine ran through a series of S.M.A.R.T. tests, and the hard drive that appeared damaged is perfectly normal.

The moral of the story: always checks your cables!

Friday, August 7, 2009

Displaying Random Text in Gnome Terminal

The other day a friend of mine asked how he could randomly display famous quotes on his Gnome terminal. He wanted a famous quote displayed every time a new Gnome terminal was started. I went over the steps of how to implement this on his box using BASH, and thought it would be an interesting first topic for this blog.

Setting this up only requires a few lines of code. For this example, I am using BASH, the default shell for Fedora and Ubuntu. Undoubtedly, it wouldn't be difficult to adapt this setup for the CSH, KSH or any other shells the reader may be using.

Upon logging in to the computer, or starting a terminal, the contents of the ~/.bashrc file are read and executed. ~/.bashrc is a user specific file, where aliases and user preferences can be set, as well as the PATH and other important variables. I have even go so far as to include functions in my bashrc file (which is preferable to aliases under most circumstances, another blog post perhaps)

My solution was to select a random number from 1 to the line count of the file (i.e., the number of quotes in the file), then print that line of the file. For the first part, I needed two lines of code. Let me introduce the second line of code first, then I'll introduce the first line (the following code snippet won't work without the first line)
let RAND=${RANDOM}%${lines}+1
That was an arithmetic expression in BASH. Rather convoluted and difficult to read, but I find it preferable to the other method (which is downright nasty!) What it does is simple. It takes the modulus of a random number by the number of lines in the file. The modulus is the remainder in a division operation. For example, 3 % 2 results in 1. 1 is the remainder when one divides 3 by 2. The importance of this operator, is it creates an upper bound. For example, x % y will produce a number from 1 to y-1. Or, in plainer English, if y were 5, I would always get a number from 0 to 4. If y were 100, I would always get a number from 0 to 99. If I divde a random number by the number of lines in the file, say 50 lines, I will get a number 0 to 49. The rest of the expression adds 1 for a number of 1 to 50, which can be matched directly with one of the fifty lines. In short, I always get a random number that coresponds with a line in the file.

With that explained, a little more detail is in order for:
${RANDOM}%${lines}
RANDOM is a variable, so is lines. The dollar sign and curly brackets expand the variables. For example, if RANDOM was 61000, and lines was 200, that expression would become
61000%200
RANDOM is a random number generated by the computer. To get a feel for the range of numbers it produces, you could bring up a terminal, and repeatedly enter:
echo ${RANDOM}
With five runs I received the numbers:
412
12859
20649
18377
21323
Your numbers will most likely vary.

The variable lines, however, is a user defined variable that I made. If you were to run that line above as is, you would get an error, something like:
bash: let: RAND=15801%: syntax error: operand expected (error token is "%")
The reason is, the variable lines is empty. The error message gives a clue, following "bash:" is what BASH tried to execute, followed by a description. Basically, it said the operator % expected an output on both its left and right side, but didn't.

Now we need the first line of code to the my working solution. The first line of code defines the variable lines.
lines=`wc -l famous_quotes.txt | awk '{print $1}'`
As with the last line of code, there are many steps to this line. The first part is `wc -l famous_quotes.txt`. `wc` is used to count words, bytes, characters and lines in a file. For fun, try `wc -w`, `wc -c` on text files to print out the amount of words or charaters. Anyhow, the command takes a file called famous_quotes.txt and counts the number of lines in the file. What I want it to do, is provide a single number for the variable lines. But instead, it produces an output of:
6 famous_quotes.txt
Which is the line count of the file proceeded by the filename. I want a number though, not a filename. So I send its output to another utility called awk. Using the bar (the | symbol) is a pipe. It sends the output of one command to another. In the past I have written expression that involved nearly a dozen pipes. You can feed the output of one command as input to another, which goes on to the next command, followed by the next, and so on.

Moving away from my digression, the output of `wc` produces unwanted output. The solution? Pipe it to a utility that formats the output: awk. Awk is a very powerful tool, and I am not even going to begin to explain its complexities here. I will only provide the most basic coverage to understand it in this context alone.
wc -l famous_quotes.txt | awk '{print $1}'
Awk operates on each line it receives, and here prints out the correct column. The output of the above would be:
6
You could change the command to `wc -l famous_quotes.txt | awk '{print $2}'` and receive an output of:
famous_quotes.txt
In other words, $1 and $2 respond to the first and second columns of the line. Of course, you can combine outputs `awk '{print $1 $2}'` or even `awk '{print $1 " " $2}'`. Awk determines each column by the variable FS (Field Separator), which you can set. But already I have far transgressed the scope of this article. For more details, use google. Awk is horrifically powerful (for those interested in text manipulation, also review grep and sed and learn to pipe the output of one to another).

So now we have our number. And in this example, it is 6. But how do we assign it to the variable lines? That is where the backticks come in. If we were to write the code naively:
lines=wc -l famous_quotes.txt | awk '{print $1}'
It would fail. We must encapsulate the commands. We do this with the backticks (for my keyboard it is adjacent to the ESC key and number 1 key).
lines=`wc -l famous_quotes.txt | awk '{print $1}'`
All the backticks do, is they execute whatever is within them, and return the result. In this case, it is assigned to the variable lines.

Now we have our two lines. The following two lines of code should work provided that the file famous_quotes.txt exists and has some lines of text in it.
lines=`wc -l famous_quotes.txt | awk '{print $1}'`
let RAND=${RANDOM}%${lines}+1
But...it doesn't print anything does it? Let's add the last line to make it print. But first, a slight discursion. The utilities `head` and `tail` are very useful tools. `head` will print the "header" of a file, or the first 10 lines. You can adjust how many lines it prints of a file by `head -30`, which would print the first 30 lines. Similarly, `tail` prints the last 10 lines of a file. Now for the final line of code:
head -${RAND} famous_quotes.txt | tail -1
RAND was defined on the second line of code, a random number within the bounds of the total count of the famous_quotes.txt file. Let's pretend RAND is 5, then the command becomes:
head -5 famous_quotes.txt | tail -1
This prints the first 5 lines of the file. But we only want the fifth line. Hence, we pipe the output to `tail`, which only prints the last line: that is, the fifth line. Hence, the solution is:

lines=`wc -l famous_quotes.txt | awk '{print $1}'`
let RAND=${RANDOM}%${lines}+1
head -${RAND} famous_quotes.txt | tail -1
Add that to your .bashrc file (and be sure to fill out your famous_quotes.txt file!) and next time you start a terminal, you will see one of your quotes!