Changing UNIX shell without actually changing it

Very rarely, I encounter a computer system I have to use regularly, but I don’t have superuser status on. Notably, at Uni, I have access to a SunOS system, where I actually have to use it from time to time. Most of the time this is just via ssh, but sometimes it’s a physical login to a SunRay workstation.

I much prefer bash over other shells, not because it is necessarily better, but that it is just the one I use most of the time. I’ve got some nice systems to help me out, like using a different colour for the user@host string on each machine, so I can easily see which machine the current ssh session is actually logged into.

However, at Uni there are lots of restrictions. We can run /usr/bin/bash, but we can’t change our default shell to it. In fact, we can’t change our default shell at all, which is kinda dumb. I’ve tried all sorts of tricks, but I just can’t do it.

The next step is to have your .login, or whatever, run the shell you want. For me, this is safe-ish, since tcsh (the current default shell) executes the contents of .login, but bash doesn’t. If you are using one shell that uses a particular login or profile file, and you want to change to another which uses the same file, you might struggle, or get stuck in an infinite loop. Which is probably worse.

Just having /usr/bin/bash -login in your .login file will then cause bash to run, and execute the contents of your .profile: without the -login it won’t execute the contents of said file. But what about when you exit the bash shell, using Ctrl-D, or exit, or logout, or whatever?

If you put a logout after the /usr/bin/bash -login line will cause the original shell to logout immediately after leaving the bash shell. Which is exactly what we want.

Now, all I need to do is figure out how to get rid of the line that says : tcsh: using dumb terminal settings.

That one’s too easy. Use xterm instead of xterm-color in the Settings➞Advanced area of the Terminal Preferences:

xterm-color.png

zsync

zsync is a file transfer program. It allows you to download a file from a remote server, where you have a copy of an older version of the file on your computer already. zsync downloads only the new parts of the file.

From zsync

Noted for future reference.

Archie In… A Different Class!

ArchiePeople13.jpg

From Chris’s Invincible Super-Blog » Blog Archive » Archie In… A Different Class!

Abyss & Apex : Fourth Quarter 2007: Wikihistory

everybody kills Hitler on their first trip.

From Abyss & Apex : Fourth Quarter 2007: Wikihistory

This had me in stitches.

Database Management

Databases are interesting. That’s not really what I mean, databases are kinda boring. But necessary.

Accessing databases, however, can be interesting. Not in the sense that it is something you’d like to be spending time on, but more in the “May you live in interesting times” Chinese curse sense.

I know enough about databases to design simple ones, and access complicated ones using something like SQL. I’m not saying I’m an SQL Wizard, but I can generally fudge around enough to actually get at the data I want. It’s really something I’d rather not do, fiddle around in SQL, but sometimes it’s a necessity.

I do like tools that make accessing databases more “fun”. There are two types that I’ve been using a bit lately.

The first are wrappers that make database tuples appear as objects. For instance, SQLAlchemy in python, and Java Entity Classes allow you to basically fetch an object from the database, operate on it, and ensure that the data is pumped back into the database. It’s a really neat way to handle data, and allows great persistence of objects in OO programming.

The other is a GUI tool designed for accessing a particular DBMS or set of DBMSs. For instance, MySQL comes with an administrator program, which does a passable job. Lately, however, I’ve been required to access a PostgreSQL database. And there is a great tool for that: Navicat. With the latest version, you can even access a PGSL database over an SSH tunnel, all without having to set the tunnel up yourself.

For instance, I have a machine at my work that I can ssh into, but I can’t directly access the development machine that has the PGSL database on it. I can set up the database as if I were on the work LAN, and then set up the SSH tunnel into the machine I can access. First time, without any hassles, and I was connected to the database. Securely. Over the internet.

I also tried another application I downloaded. But it was written in Java.

Java apps on the Mac really don’t fit. I haven’t used too many on Windows, but as soon as you launch a Java application in OS X, you know it’s a Java app. It doesn’t feel right. It doesn’t use the right file open and save panels. That have all of my shortcuts that make it possible for me to work on several different projects and keep sane, and well organised.

I’ve fiddled with a couple of other Java apps, and almost without exception I have thrown them out immediately. There was a clunky merge application, which lasted one run. Same with PowerArchitect. It just interferes enough with my workflow that I can’t make it happen.

Hell, it seems like a well-written application written for Windows, and running in Wine or VMWare seems to feel better than just about every Java application I have ever used. Well, maybe not every one. I guess a Java application that didn’t feel like a Java application would slip under my radar.

Which is what I’d want.

Stupid Teachers.

I think I can say that, since I used to be one.

I guess having been a teacher means I know how to spot when one isn’t really prepared, or doing their job properly, or just plain incapable.

I’ve got some teachers, both lecturers and tutors, who I don’t really have much time for.

There are a few things I really dislike. The first is obnoxiousness. I have one lecturer who is not only obnoxious, but also boring. He can spend a whole lecture teaching a tiny amount of content, and perhaps this is why he is so boring. He is also dry, and does not use examples to elaborate particularly well. His worst trait is probably the questions he asks. It is never clear whether a particular question is a rhetorical question or not. Finally, he seems to think that it is acceptable to just discard all negative feedback that he receives, as it is “probably invalid”, or the person “just has a grudge”. Never mind that you are just a crap teacher.

The next thing I dislike is when someone is teaching something they don’t really know that well. This is definitely a place I have been, having to teach stuff I didn’t really know about. I have one tutor who as much as said several times there were things he didn’t understand. I’m paying good money to go to Uni, I don’t want to waste that, or my time. At one stage, when I knew I was right about something, and he wasn’t really listening to what I was saying, I basically gave up and let him continue. I know (that with a ternary relationship total participation isn’t automatically implied), and I think now that the rest of the class thinks that it is.

My third annoyance is to do with general organisation. I hated being poorly organised when teaching, and did my best to overcome this issue. I know at times I didn’t and it really embarrassed me to be the one who was at fault. Not having work prepared ahead of schedule, not being on time, these are all things that turn off the good students, perhaps more so than the bad students!

My final gripe is about… I’ve forgotten what I was going to write next.

Great system. Almost.

Last night, after Uni, I went to the supermarket to buy a few things. BBQ chicken is always worth a couple of meals, so I thought I’d grab one of those. There was a short-ish line for the deli, so I used the whizz-bang new touchscreen system to place an order for a small BBQ chicken. It printed out a little voucher, which promised me a coffee on the day of printing only, and which I could also use to collect my goods.

There was a counter that I assumed was where you go to wait for the express-style ordering, so I went over there. A couple of minutes passed before someone asked me if I was waiting for something. I pleasantly said yes, I had ordered a BBQ chicken, and dutifully gave her the number on my voucher.

The next (fat, but that’s immaterial) girl took one look at me, and just said “we don’t have any.”

I said “Super. Does your feeder know you have gone out.” No, I really said “Well, that’s pretty silly. Your automated system should have told me there weren’t any left.”

She haughtily replied, “Yeah well, the system doesn’t work properly.”

This raises lots of questions in my mind. The system in question stands to really improve a shopping experience - it means you have to deal less with people (and let’s face it, people are dumb). It also should make things quicker, and less hassle free. Instead, I walk away vowing not only to not use the system again, but to abuse it. (Can anyone say, I just printed out 30 BBQ chicken orders, and used the vouchers to get 30 coffees I threw away out of spite?)

Mmmm. Bunnylicious.

via Whatever

ulimit and time

For a Uni project, I have to write the same algorithm different ways, and in different programming paradigms. I also need to collect data on the execution of said programs. Since some algorithms may run in large time on large data sets, I need to stop execution after 30 minutes of run time. And, since there needs to be between 50 and 64 runs of each data size, I wanted to automate the process.

Using the $ time `other-command` is the most obvious way to time execution of any command line application on any decent operating system. However, the time that comes with OS X is somewhat limited - from the man page:

NAME

time – time command execution

SYNOPSIS

time [-lp] utility

It only has two options, and they aren’t that useful. However, it is possible to use this command to time execution.

Because it outputs it’s timings to stderr, then you need to do some tricky python to capture it and save it to a file. I used sys.popen3(), and then read from the stderr stream. Which worked okay, but there isn’t really a way to stop execution after a certain time frame. You can try to use TimeoutFunctionException - which I can’t remember where I got it from, but it’s cool. It doesn’t work in this case, since the sys.popenX calls run in a sub-process, and thus continue to run after the exception is raised. Fail.

About this time in my thought process, I came across a better time. GNU time allows you to select the output format (excellent, no need to parse the output quite so much!), and to output to a file instead of stderr/stdout (even better). It also allows to append to a file instead of overwriting, and some other cool stuff.

But it doesn’t solve the issue of commands running too long. This was a killer, since the process continues to run, but worse than this, new processes are started. So the machine clogs to a virtual halt.

Then I came across ulimit. This handy tool can limit the resources a user or process is able to use.

$ ulimit -t X; time -f %U -a -o {DATAFILE} {COMMAND} {ARGS}

This command will limit a command to X seconds (or slightly less, since the time command itself uses some time. It will then execute COMMAND, with arguments ARGS, and time the execution, appending the run time only, on a seperate line, to the file DATAFILE.

Note that this is no excuse for not using code profiling. I have already run profile.run() on my code to work out where the slowdowns are in the python versions, and then optimised them. This is more like the last phase, actual comparisons.

Remote Support: TeamViewer for Mac

Doing support isn’t that much fun, however, at times it needs to be done. Until today, I used to have to either fire up a VMWare session, or run Darwine (or CrossOver) in order to run TeamViewer on my Mac. But today, when I went to the TeamViewer website, and they have a beta version of their client for OS X.

I haven’t had the chance to use it in anger yet, I nearly had to today, but managed over the phone instead.

What I did do for the first time yesterday is use IM for work specific purposes. That was kind of fun. And the cool thing about Adium is that it keeps logs of my chat with my minion, so when I bill my boss for the time spent on the tasks, I have evidence.