Posts Tagged ‘ Bash

Ubuntu – change custom screensaver text

The default text in the GLText screensaver in Ubuntu is “Host-Name, Kernel Version”. To change this, go to the screensaver folder in the terminal, and copy the gltext.desktop file to your home directory. Open gltext.desktop for editing (using emacs, for example), and change the line that reads:

Exec=gltext -root

to

Exec=gltext -root -front -text 'whatever text you like'

Might need to change permissions. I just ran chmod 777 and that did the trick.

This worked for me using Ubuntu 10.04 (Lucid Lynx).

MB-System and missing link flags

Thanks for the tip, Kurt!!

I guess this is probably a painfully obvious solution to anyone who knows what they’re doing, but it turns out I was missing the link to GDAL in my install_makefiles script. There’s a line in there that looks like this:


$LFLAGS = "-L$NETCDFLIBDIR -lm -lnetcdf";

It should have had a link to GDAL like this:


$LFLAGS = "-L$NETCDFLIBDIR -lm -lnetcdf -lgdal";

So it worked! It ran with no errors, and seemed to build correctly. So one step closer! I then continued along the instructions to setting the .bashrc file. I had left out one line before, so I added it, and then ran:


$ source .bashrc

To test my GMT and MBSystem installs, I tried:


$ psxy
$ man psxy
$ mbgrid
$ man mbgrid

Since I don’t know how to use GMT and MBSystem yet, I don’t know if these did what they were supposed to. But it seemed like they did, except for mbgrid, which came up with an error: “Unable to open data list file: datalist.mb-1“. But at least it recognized mbgrid as a command and tried to do something!

Ah, finally, I’m getting somewhere! :-)

Linux – save output to a file

I just tried running David’s script, and a waterfall of numbers flew by the terminal window.  Too many – I couldn’t scroll up to the beginning to see if the script was doing what I thought it was.  So how to direct output to a file?  A quick Google search brought me to this site, and below is the useful part:

Standard output >

Many Linux commands print their output to screen. For example, ls does this when it lists the contents of a directory: you see the output, the directory listing, on your screen.cat does the same: it concatenates a file and sends the results to your screen, and thus you can see the file’s contents. But the screen isn’t the only place where the commands can print their output because you can redirect the output of several commands to files, devices, and even to the input of other commands.

The CLI programs that display their results do so usually by sending the results to standard output, or stdout for short. By default, standard output directs its contents to the screen, as you’ve seen with the ls and cat commands. But if you want to direct the output to somewhere else, you can use the > character. For example, to redirect the output to a file, you can use the > character like this:
ls > dir_listing.txt

The above redirects the output of the ls command to a file called dir_listing.txt. Because the output is redirected to a file, you don’t see any results of ls on your screen.

Each time you repeat the above command, the file dir_listing.txt is overwritten with the results of the ls command. If you want to append the new results to the file instead of rewriting it, you can use >> instead:
ls >> dir_listing.txt

Each time you repeat the above command, the new output of ls is added at the end of the dir_listing.txt file instead of overwriting the file.

The following adds the contents of File1 at the end of File2:
cat File1 >> File2

Like I told you before, files aren’t the only places where you can redirect the standard output. You can redirect it to devices, too:
cat sound.wav > /dev/audio

As you saw, in the above example the cat command concatenates a file named sound.wav and the results are sent to a device called /dev/audio. What’s the fun here, then?/dev/audio is the audio device, and when you send there the contents of a sound file, that file is played. So if your sound is properly configured, the above command plays the file sound.wav!

Once I did that, I was able to save the file, and I could see that it was, indeed, doing what it was supposed to be doing (of course it was – it was only a matter of me figuring out how to look at it!).

Here’s the top part of the output (before it turns into a waterfall of numbers):

Bytes: 396 RecordType: 7200 fragmentNumber: 0
Bytes: 4613 RecordType: 7001 fragmentNumber: 0
Bytes: 4837 RecordType: 7000 fragmentNumber: 0
Bytes: 13109 RecordType: 7004 fragmentNumber: 0
Bytes: 21905 RecordType: 7006 fragmentNumber: 0
Bytes: 33072 RecordType: 7027 fragmentNumber: 0
%% DATA RECORD FRAME (11167) bytes
ProtocalVersion: 5
Offset: 60
Sync Pattern: 65535
Size: 11167
Optional Data Offset: 0
Optional Data Identifier: 0
Year: 2009
Day: 353
Second: 55.214169
Hour: 17
Minute: 53
Record Type Identifier: 7027
Device Identifier: 7125
System Enumerator: 0
Flags: 32769
Total Records In Fragmented Data Record Set: 0
Fragment Number: 0
DATA SECTION: 11099 (bytes)
Checksum: 788564
--- Data Section --
(Detection Properties Record)
Sonar Id: 0
Ping Number: 0
Multi-Ping Sequence: 0
Points(?): 500
Size(?): 22
Sample Rate: 34482.757812
Transducer Angle: 0.000000

It’s sonar data! It really is! Okay, mostly header info, but still… It’s probably a bit silly to be this excited about simply running someone else’s program. But I had to figure out at least 4 or 5 things just to get to that point, so it’s not a wasted evening, right?  :-)

Auto-complete in bash using up-arrow

In Matlab, the up-arrow auto-completion is smart, so it not only goes through the command history, but if you start typing something, then type tab, if there’s a match in the history, it will pop up.  I was looking for a way to do this in bash, and I found that if you type ctrl-R, it lets you search.  It’s almost as easy, but not quite :-)  But I think I can get used to it.

Another attempt at installing GMT and MB-System

After getting some advice from Monica I felt I was ready to attempt installing GMT and MB-System again.  It looks like my problems might have been due to some incorrect path names.  My install_gmt script keeps crashing in the same place – at the part where it looks for GDAL files (ie gdal.h, and others).  I think it assumes that GMT lib and include subdirectories are under the same folder.  This doesn’t seem to be the case when I used the default Synaptic install.  So I uninstalled it, and am trying to install from source.

I grabbed the tar file from here:
http://download.osgeo.org/gdal/gdal-1.7.1.tar.gz

I extracted it, navigated to that directory in a terminal window, and ran the following commands:
./configure
make
sudo make install

Summarizing what these do:
./configure: checks for required dependencies, reports an error is they’re not there
make: compiles the source code
make install: installs the program

This time, my GDAL lib and include directories were put into /usr/local. Unfortunately, they are also still in the previous location, and I think I will need to manually remove them.

I added a couple of things to my .bashrc environmental variables – including the MANPATH, and the NETCDF path.

Next – installing MB-System! Finally!

First I installed the following packages using apt-get install:
xorg-dev
libmotif-dev
libxp-dev
mesa-common-dev
libsdl1.2-dev
libsdl-image1.2-dev

Downloaded the MB-System.tar.gz file from the ftp site.

…to be continued

Installing GDAL

Last night I didn’t finish installing GMT because I wanted to make sure I had access to GDAL (Geospatial Data Abstraction Library). I got it by running sudo apt-get install gdal-bin. I am not entirely certain if that was the right thing to do. And if it does install GDAL, I’m not sure what version it will be. (I think it’s 1.5?)

It installed and I ran the GMT install file again, this time choosing the GDAL option and specifying the appropriate path. Seemed like it worked at first…but I now think I’m worse off than ever…

I think maybe my problem is that I don’t know where my installed folders are going. I just found this little hint:

sudo updatedb
locate gdal

This command returned a ton of lines – I guess that means I have a lot of files and folders on my computer that contain the string “gdal” in their title. Anyway, this was enough to show me where to find my elusive GDAL directory. (it’s in /usr/share/, it’s called /gdal15).

I also tried to use this to find my netcdf directory, since that was also giving me similar errors during GMT installation. But there are so many netcdf files and folders that I don’t know which one is the installation folder. I need to figure out how to install things where I want them.

I finally just ran install_gmt without the GDAL option. I think it went okay, except for a bunch of warnings and errors at the end about “gmt_support” and the triangulate function.

*sigh* … I still have a lot to figure out. I’m at that stage where every question I ask raises about 10 new questions.

Installing GMT

(Warning: This is a long, and probably confusing post. Read at your own risk!)

My life for the last 7 years has basically revolved around oceans and maps in one way or another.  Since I’m now trying to embrace the wonderful world of open source, I thought it would be a good idea to combine my passions and finally figure out GMT and MB System.  I thought this tutorial on installing MB-System on Ubuntu would be helpful, but I was doing something wrong and couldn’t even get past the very first step.

So the way it works is that on the GMT home page, you can use a form to automatically generate a script that you can save as a text file and use as an argument to the install_gmt command. I tried to do this for (literally) hours. I kept getting an error message about how it couldn’t find my netcdf directory. So a couple of minutes ago, I finally ran the install_gmt script without the GMTparams.txt argument, and I think I got a little further. It installed the necessary netcdf stuff, appeared to be installing GMT, and then gave me errors about not being able to find some files or directories. I think that the errors were all related to a missing GDAL directory. The GDAL thing is an optional feature that you can set up during installation that is supposed to allow you to create geo-tiffs. But I think I must haave set it up wrong…

So in the end, I am not certain whether I successfully installed GMT or not. But it’s now getting too late, and I’m too tired to figure it out. To be be continued…

**** a bit later *****
Ah-ha! I started the installation again found this little tidbit:
GMT offers experimental and optional support for other grid formats
and plotting of geotiffs via GDAL. To use this option you must already
have the GDAL library and include files installed.

I think this means it’s getting late and I’m starting to miss obvious things. More tomorrow!

SQLite configuration file

I just created a simple configuration file for SQLite. It’s in my home directory, and is called .sqliterc. It contains the following lines:

-- SQLite configuration file
.echo ON  # repeat every command
.header ON  # print column names
.separator  "\t" # change default separator to tab
.nullvalue "Null" # print the word rather than having empty fields

Now, every time I start SQLite, these commands will be run.

* Thanks to Kurt, who showed me how to do this!

2010-02-10
** NOTE: Correction has been made to .sqliterc –> # (pound signs) are NOT comments in this file. I need to use — (two dashes) to signify a comment. I was getting an error if I didn’t do this. Not sure why I didn’t catch this way back when I wrote this post.

bzippin'

So, here’s another one of my posts where I describe how to do a painfully easy thing, simply because it’s the first time I’ve ever done it. Today it’s How to Compress a File Using bzip2!

SO EASY:

bzip2 [-options] [filename]

Options are described here. But if you are not worried about options and want to use the default, it’s this easy:

bzip2 superfile.foo

Unzipping is easy too:

bunzip2 superfile.foo.bz2 or bzip2 -d superfile.foo.bz2.

Bash and the 'find' command

As a fairly new Linux user, I am constantly confronted with things that I should know but don’t… making it all the more fun :-)    Looking up some Bash basics, I came across this little tutorial on an Ubuntu forum – “A gentle introduction to ‘find’.  Just the kind of introduction I like, at least to a fundamental Linux command line tool.