bash


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
View Comments (0)   RSS Feed for Comments on this Post

Thoughts of the Bored » Archived Thought » UNIX palindromes #1

There exist a “test” command and a “tset” command, but tset does not do the reverse of test. I consider this a lost opportunity.

View Comments (0)   RSS Feed for Comments on this Post

bash:

mdls filename | grep FinderComment

AppleScript:

tell application "Finder"
    comment of file
end tell

python:

#!/usr/bin/pythonw
from appscript import *
path = '/Users/NAME/your/path/here'
comment = app('Finder').items[path.replace('/', ':')].comment.get()

View Comment (1)   RSS Feed for Comments on this Post

An even better method of getting a random (ascii) password:

$ head /dev/urandom | strings -n 5 | sed 'N;s/$//;s/\n//g;s/\n//g' | sed 'N;s/$//;s/\n//g' | head -n 1

(All on one line, naturally).

I had to do the two seds to make it work properly. It would have been nicer if this combined all of the lines, and then I could just trim as many chars as I wanted, but this was tricky. The head -n 1 discards any lines other than the first.

View Comments (0)   RSS Feed for Comments on this Post

I needed a nice random password, something that is fairly strong. Enter /dev/urandom and md5:

$ head /dev/urandom | md5

e98afcb4f093bafa0cc5f90f150df8b7

Obviously, that’s not the password I used.

Problems with this method: if you don’t write it down, or save it somewhere, you will not be able to get it back. Second, it only uses a small subset of the ascii codeset - 0123456789abcdef. I’ve tried to come up with something that converts this to ascii, but I’m still working on it. You’d also likely want to ignore 8-bit values, as these can be extended characters. If you ever needed to type this in, it’s sometimes hard to do.

The big advantage is that this is a totally random method, and you won’t get the same code twice.

View Comment (1)   RSS Feed for Comments on this Post

I’ve borrowed a laptop from work, and a Wireless Access Point device, so now I can do stuff from my bedroom late at night, like I am this.

However, just recently I have come across some sort of strange behaviour. Sometimes, but not all of the time, MacOS’s Internet Sharing feature seems to get turned off. Which means I need to get access to the machine and restart it. Not much fun when I’m all toasty warm in bed, and the Mac is in the cold, cold study.

So, I’ve done a little bit of research.

I might be able to restart it using:

$ sudo /usr/libexec/InternetSharing

I’ll try that next time it drops out… but I’d rather have a better fix.

View Comments (2)   RSS Feed for Comments on this Post

Whenever I need to do any calculations, I generally drop into python and do them from there. However, I came across a neat tip over on Mac Geekery: When You Need A Calculator.

I’ve modified is ever so slightly so it goes into a .profile instead of a .bashrc:

function calc
{
    awk "BEGIN {print $* ; }"
}

Sweet.

View Comments (0)   RSS Feed for Comments on this Post

Occasionally, the ABC have items on their programs to which they don’t have the copyright for, and as such they cannot post an MP3 of the program, but will do a Real Audio stream. Meaning you have to use Real Audio to listen to it, and you cannot archive it.

Or so it seems. Now, I refuse to use Real Audio: it’s nothing to do with commercial software or anything like that (there is after all a free version), but I just don’t like streaming. I find that on dialup it just doesn’t work well. And, the time I spend at the computer I am generally reading, so listening to anything other than music just doesn’t work well. I much rather listen to Podcasts while commuting.

So, how do you get an item into your iTunes Podcast library?
(more…)

View Comment (1)   RSS Feed for Comments on this Post

The following function/script will dump the data from a RealPlayer stream to disk as a WAV file.

Put it into your ~/.profile, or make a shell script out of it.

function realdump
{
    if test -f $1 ; then
        realdump `cat $1`
    else
        export temp=${1/#*\//}
        export filename=${temp/.*/.wav}
        ~/bin/mplayer -cache 128 -vc dummy -vo null -ao pcm -aofile $filename $1
    fi
    if test $# -gt 1 ; then
        shift
        realdump $*
    fi

}

It creates a file with the same basename (the filename minus the extension), with an extension of .wav; there is no checking to see if the file exists already, and old file will be overwritten.

The argument to realdump can be either the URLs of the streams, or the name of a file with the URLs of the streams in it. It should handle files with multiple entries, so you can concatenate a series of .ram files, and it should download each of them in turn. Ensure they have different filenames, not just different directories!

View Comments (0)   RSS Feed for Comments on this Post

I really like the way Apple decided to ‘package’ applications, plugins and the like with MacOS X. It actually makes it easy to see how stuff works. Take basic applications, and most of them are just an executable, but it’s easy to add modularity, and replace GUI elements and so forth.

I’ve grown tired of Toast: it seems to fail more than half of the time when burning DVDs, and I know the media is good, because Disk Utility has no problems burning! I intended to make an AppleScript that burned the selected disk image to a DVD/CD, but found that Disk Utility was not scriptable. But there exists a CLI command called hdiutil that can do most of the stuff Disk Utility can (at least with disk images).

The command to burn an image to a Recordable Drive is:

hdiutil burn <imagename>

All I need to be able to do is get this to happen as a contextual menu. As far as I can tell, it should be possible to do this from AppleScript, or python, or bash. Even better, I should be able to automatically create the <Name>.plugin/* directory structure, and what the contents need to look like, as soon as I can find out exactly what needs to be where!

View Comments (0)   RSS Feed for Comments on this Post

Next Page »