Technology Tales

Adventures & experiences in contemporary technology

Putting it all on one line

9th March 2008

One of the nice things about the Linux/UNIX command line is that you get the options of stringing together a number of commands on one line for submission of all for processing at one go. Separating them with && does the trick but I noticed that semicolon delimitation worked as well. Here’s a line that will install VMware for you in one fell swoop:

sudo apt-get install linux-headers-$(uname -r) build-essential gcc-3.4 && tar xzf VMware-workstation-6.0.2-59824.i386.tar.gz && export CC=/usr/bin/gcc-3.4 && cd vmware-distrib && sudo ./vmware-install.pl

Another trick is to direct the output of one command into another like the following which subsets a process listing:

ps -aux | grep "wine"

It’s all good stuff and is the sort of thing that shows why so many Linux/UNIX types love their command line so much.

iPod, identified

9th December 2007

Plug in an iPod to a PC running Ubuntu and it will recognise what it has got. That act mounts the player as a hard drive and fires up the Rhythmbox Music Player. The usual file transfer capabilities are available and it does something that was thwarted partially by iTunes when I last tried it: transferring files from your iPod to your PC. Only music bought from the iTunes store can copied from the player back to the PC. Unsurprisingly, you cannot update the iPod’s firmware or anything like that. To do such things, you need the iTunes player and that means having either Windows or OS X. While I do wonder if it can’t be that hard to port the OS X version to Linux since they both share UNIX roots, it’s over to the Windows VM for me on this one for now.

Connecting to Host USB Devices from VMware

However, while VMware on Windows will happily pick up USB devices as they are connected so long as the VM is in focus, the behaviour on Linux seems to be different. As shown above, you have to go to the VM menu and potter down the chain (Removable Devices > USB Devices) to make the device of interest accessible. Dialogue boxes asking you if you want to disconnect the device from the host operating system will appear and the process may be unsubtle as you progress with it. In fact, Ubuntu was delivering warning messages about how its iPod connection got lost; it would have been wise to unmount the thing in the first place. Accessing USB devices like this opens up other possibilities: using Windows for scanning and for printing digital images.

Returning to the iPod story, Windows will see it once it has been made available and iTunes can access it accordingly. Then, you are free to update the gadget’s firmware or manage the music stored on it, if you prefer.

About workspaces…

16th November 2007

One of the nice things about the world of Linux and UNIX is the availability of multiple workspaces. In Window, you only ever get one and the likes of me can easily fill up that task bar. So the idea of parceling off different applications to different screens is useful from a housekeeping point of view so long as icons only appear in the task bar foe the open workspace; Ubuntu respects this but openSUSE doesn’t, a possible source of irritation.

However, a case can be made that UNIX/Linux needs workspaces more than Windows because of the multi-window interfaces of some of the software applications. The trouble with each of these sub-windows is that an entry appears in the task bar for each of this, creating a mess very quickly. And it can also be an issue working out which window closes the lot.

Examples of the above that come to my mind include GIMP, XSane and SAS. The Windows version of the latter’s DMS is confined to a single application window while the UNIX incarnation is composed of a window each for individual components like program editor, log, output, etc. Typing "bye" in the command line of the program editor is enough to dispatch the GUI. With GIMP, Ctrl+Q will close it down in any window apart from the "Tip of the Day" one that pops up when GIMP is first started. The same sort of behaviour also seems to dispatch XSane too.

Switching form one workspace to another is as easy as clicking the relevant icon in the task bar in all of the UNIX variants that I have used. Switching an application from one workspace to another has another common thread: finding the required entry in the application window menu.

In Ubuntu, I have seen other ways of working with workspaces. In the interface with visual effects turned off, hovering over the workspace icons in the task bar allows you to move from one to another with the wheel of your mouse. Moving an application between workspaces can be done as simply as dragging boxes from one task bar icon to another. Turning on the visual effects changes things, though. It might appear that the original functionality still works but that seems not to be the case: a matter for Canonical to resolve, perhaps?

The visual effects do provide other ways around this though. Keeping all your application windows minimised means that you can run through workspaces themselves with your wheel mouse. Moving applications between workspaces becomes as simple as grabbing the title bar and pulling the window left or right until it changes workspace. Be careful that you do the job fully though or you could have an application sitting astride two workspaces. It would appear that ideas from the sharing of a desktop across multiple monitors have percolated through to workspace behaviour.

Aside (regarding Ubuntu visual effects): I don’t know who came up with the idea of having windows wobble when they’re being moved around but it certainly is unusual, as is seeing what happens when you try prising a docked window from its mooring (particularly when you’re pulling it up from the bottom task bar). The sharper font display and bevelled screen furniture make more sense to me though; they certainly make a UI more appealing and modern.

A UNIX shell running on Windows

15th November 2007

Here’s an idea that I got for a post before I spent that torrid weekend with Windows that caused me to jump ship to Linux. The idea of having a UNIX command line while still remaining in Windows did appeal to me at the time and Cygwin seems to provide an intriguing way to do this. At its most basic, it is a set of DLL’s that allow you to run standard UNIX commands in a shell like what you see below. However, it is extensible with a good number of packages that you can choose to install. NEdit is just one that gets included and I think that I spied Apache too. The standard installation is a web-based affair with your downloading only the components that you need; it’s worth trawling through the possibilities while you’re at it.

Cygwin Shell

Now that I am firmly ensconced in the world of Linux, this may be one possibility that I will park, for a while anyway. After all, I now do have the full power of the UNIX command line…

Filename autocompletion on the command line

19th October 2007

The Windows 2000 command line feels an austere primitive when compared with the wonders of the UNIX/Linux equivalent. Windows XP feels a little better and PowerShell is another animal altogether. With the latter pair, you do get file or folder autocompletion upon hitting the TAB key. What I didn’t realise until recently was that continued tabbed cycled through the possibilities; I was hitting it once and retyping when I got the wrong folder or file. I stand corrected. With the shell in Linux/UNIX, you can get a listing of possibilities when you hit TAB for the second time and the first time only gives you completion as far as it can go with certainty; you’ll never get to the wrong place but you may not get anywhere at all. This works for bash but not ksh88 as far as I can see. It’s interesting how you can take two different approaches in order to reach the same end.

On numeric for loops in Korn shell scripting

18th October 2007

The time hounoured syntax for a for loop in a UNIX script is what you see below and that is what works with the default shell in Sun’s Solaris UNIX operating system, ksh88.

for i in 1 2 3 4 5 6 7 8 9 10
do
        if [[ -d dir$i ]]
        then
            :
        else
            mkdir dir$i
        fi
done

There is a much nicer syntax supported syntax the advent of ksh93. It follows C language conventions found in all sorts of places like Java, Perl, PHP and so on. Here is an example:

for (( i=1; i<11; i++ ))
do
        if [[ -d dir$i ]]
        then
            :
        else
            mkdir dir$i
       fi
done

Detecting file ownership in Korn shell scripts

17th October 2007

I recently was having a play with using a shell script to do some folder creation to help me set up a system for testing and I started to hit ownership issues that caused some shell script errors. At the time, I didn’t realise that there is a test that you can perform for ownership. The "-o" in the code below kicks in the test condition and avoids the error in question.

if [[ -o $dirname ]]
then
    cd test
    for i in 1 2 3 4 5 6 7 8 9 10
    do
        if [[ -d study$i ]]
        then
            :
        else
            mkdir study$i
        fi
    done
    ls
    cd ~
fi

Previously, I shared a way to test for directory (-d operator) and file (-f operator) existence that follows the above coding convention. However, there are a plethora of others and I have made a list of them here:

 OperatorCondition
-e fileFile exists
-L fileFile is symbolic link
-r fileUser has read access to file
-s fileFile is non-empty
-w fileUser has write access to file
-x fileUser has execute access to file
-G fileUser’s effective group ID is the same as that of the file
file1 -nt file2File 1 is newer than file2
file1 -ot file2File 1 is older than file2
file1 -et file2File 1 was created at the same time as file2

It’s all useful stuff when you want to rid the command line output of errors in an above board sort of way. These are the kinds of things that often make life easier…

Negative logic in Korn shell scripts

16th October 2007

I was looking for a way to negative logic, doing something when a condition is not satisfied, that is, and found that the way to do it is to do nothing when the condition is satisfied and something when it isn’t. Being used to saying do something when a condition is false, this does come as a surprise. It may be that I find another way on my UNIX shell scripting journey. In the meantime, the code below will only create a directory when it doesn’t already exist.

dirname=test
if [[ -d $dirname ]]
then
    :    # the colon operator means do nothing
else
    mkdir test
fi

Accessing the host file system from a VMware virtual machine

9th October 2007

I am very surprised at myself for not realising until recently that there is a way to make host data visible to a guest operating system installed in a VMware virtual machine other than resorting to using flash drives, CD’s, DVD’s and the like. You can copy and paste from the host into the VM but I have found that to be hit-and-miss at times. It was a revelation to find VMware’s Shared Folders function. I suspect that you need VMware Tools installed in the guest operating system to make it work and that may not be trivial for some Linux distributions or UNIX. I was using it with a Windows 2000 guest and a Windows XP host and it worked like a dream.

What you see below are the shared folder settings in the host’s VMware interface for that virtual machine. Just clicking on the Add… button brings up a wizard that will set up the shared folder for you; it’s all very user-friendly. Look for the Edit virtual machine settings link on the VM configuration page, click that and pop over to the Options tab and this what you can get.

Virtual Machine Settings - Shared Folders

The end result of the above spot configuration appears in Windows Explorer like it does below. Not only are the shared folders accessible in this way but you can also map drive letters as if they were network resources, a very nice feature. It is definitely more accessible than working out Windows networking and getting things to happen that way.

VMware Shared Folders Displayed in Windows Explorer

A throwback to the past: an appearance of MACROGEN

4th October 2007

Recently, I was reviewing a log of a program being run by SAS 9.1.3 on a Solaris system and spotted lines like the following:

MACROGEN(MACRO1):   OPTIONS NOMPRINT NOMPRINTNEST

NOTE: PROCEDURE DISPLAY used (Total process time):
real time           0.73 seconds
cpu time            0.50 seconds

MPRINT(MACRO1):   SOURCE SOURCE2 NOTES;

The appearance of the word MACROGEN made me wonder if there was another system option that I had missed. A quick search of the SAS website threw up a support note that shed some light on the situation. Apparently, MACROGEN is the SAS v5 forbear of today’s MPRINT, MLOGIC, and SYMBOLGEN options and would seem to be obsolete in these days. Having started programming SAS in the days of version 6, I had missed out on MACROGEN and so use its replacements instead, hence my never coming across the option. Quite what it’s doing showing up in a SAS 9 log is another story: and there I was thinking that SAS 9 was the result of a full rewrite… Now, I am not so sure but at least I know what MACROGEN is if someone ever takes the time to ask me.

  • All the views that you find expressed on here in postings and articles are mine alone and not those of any organisation with which I have any association, through work or otherwise. As regards editorial policy, whatever appears here is entirely of my own choice and not that of any other person or organisation.

  • Please note that everything you find here is copyrighted material. The content may be available to read without charge and without advertising but it is not to be reproduced without attribution. As it happens, a number of the images are sourced from stock libraries like iStockPhoto so they certainly are not for abstraction.

  • With regards to any comments left on the site, I expect them to be civil in tone of voice and reserve the right to reject any that are either inappropriate or irrelevant. Comment review is subject to automated processing as well as manual inspection but whatever is said is the sole responsibility of the individual contributor.