...making Linux just a little more fun!

<-- prev | next -->

# More 2 Cent Tips!

See also: The Answer Gang's Knowledge Base and the LG Search Engine

- Just Bad and Wrong... yet cool
- BSS and Data Segment
- email issue
- Running isoLINUX from a REALLY old machine
- Tuppence Tip: URL scraper.
- Global home movies with cron and Imagemagick

### Just Bad and Wrong... yet cool

Rick Moen (LG Contributing Editor)
Question by ()
Answered By Jimmy O'Regan, Ben Okopnik

"bash is terrifying me again":
  http://www.livejournal.com/users/mendel/128965.html

`Bash pseudo-sockets: Oh my!`

followed by: "Dude, you've got a smiley in your prompt."

> [Jimmy] Followed by:

> > fishsticks$ false
> > fishsticks$

[Raj] How did he do that. I want something like that too. If anyone knows, do tell.

> [Jimmy]

>     jimregan@jimmy ~
>     $ echo $PS1
>     \[\033]0;\w\007 \033[32m\]\u@\h \[\033[33m\w\033[0m\] $

>     jimregan@jimmy ~
>     $ smiley () { if [ $? == 0 ]; then echo ':)';else echo ':(';fi; }

>     jimregan@jimmy ~
>     $ PS1="\$(smiley) \h$ "
>     :) jimmy$ false
>     :( jimmy$ true
>     :) jimmy$

> Um... I should probably explain that.

> $? holds the exit status of the last process: zero for success, non-zero for failure; $PS1 is the primary prompt.

> It's \$(smiley) because you want bash to evaluate it every time: $(smiley) would just evaluate it at the time you set the variable, as would putting the contents of the smiley function into PS1

> \h is the shorthand for \$(hostname)

> [Ben] Darn it, Jimmy, you always beat me. What, you have a fast connection or something?

> [Jimmy] My connection, in "the cheque is in the mail" speed is 115.2 Kbps, so no.

> [Ben] My way was just slightly different:

>     # More-or-less undocumented Bash-ism - a C-style trinary operator
>     smiley () { echo -e ":\\$(($??50:51))"; }

### BSS and Data Segment

Mike Zheng (mail2mz from gmail.com)
Question by tag (tag from lists.linuxgazette.net)
Answered By Lew Pitcher

Hi All,

For a program, the BSS contains un-initialized variables, Data contains initialized variables. Why do we want to separated these two categories of variables?

> [Lew] It's an optimization thing. If each binary contained an image of 'data' that included the uninitialized variables, then the binary would be larger in size than if the image did not include uninitialized variables. If you don't map these variables to your 'load image' (the contents of the binary), but instead, map them to memory at execution time, your binaries can be smaller without a loss of functionality.

> The 'typical' (conceptual) memory map (once a program has been loaded into memory) looks something like this...

>               +----------------+
>               |  stack space   |
>               |       :        |
>               |       v        |
>               |                |
>               |                |
>               |                |
>               |       ^        |
>               |       :        |
>               |   heap space   |
>               | .. .. .. .. .. |
>               |      BSS       |
>               +----------------+
>               |      DATA      |
>               |                |
>               +----------------+
>               |     (CODE)     |
>               |                |
>               +----------------+

> (on most implementations, CODE is kept in a separate address space from DATA/BSS/heap/stack)

> Heap 'grows' up from the end of BSS towards the highest address Stack 'grows' down from the highest address towards the end of the BSS Heap allocation code keeps a boundary between the top end of the heap and the bottom end of the stack.

> The 'loadable' part of the binary is the CODE and DATA part. BSS is how the loader accounts for the room needed to hold the uninitialized data.

Some program clear the BSS by itself, is it necessary?

> [Lew] A mere convenience, nothing more.

> HTH

### email issue

J.Bakshi (hizibizi from spymac.com)
Question by tag (tag from lists.linuxgazette.net)
Answered By Jimmy O'Regan, Rick Moen

Hi list,

At first I wish you all a very ******HAPPY NEW YEAR******.

Here is a technical query. Frequently I get some advertisement-emails with EMPTY "form" header & EMPTY "to" header. Even the "detail-header-view" of sylpheed-claws can't show any header information. What is the technology which makes this possible and how can we prevent such emails ?

> [Jimmy] The technology that makes this possible is called [drumroll]... SMTP!

> To see how it works, use telnet:

>     $ telnet smtp.o2.ie 25
>     220 smtp1.o2.ie -- Server ESMTP (Sun ONE Messaging Server)
>     MAIL FROM: test@example.com
>     250 2.5.0 Address Ok.
>     RCPT TO: jimregan@o2.ie
>     250 2.1.5 jimregan@o2.ie OK.
>     DATA
>     354 Enter mail, end with a single ".".
>     From:
>     To:
>     Subject: Test

>     A test
>     .
>     250 2.5.0 Ok.
>     QUIT
>     221 2.3.0 Bye received. Goodbye.

> Now, I check my mail. In Mozilla Mail, it shows up as this:

>     Subject: Test
>     Date: 11:45

>     A test

> View->Message Source:

See attached `mbox.txt`

> What'll be interesting now will be to see how many mail apps that use mboxes are broken by that }

> [Rick] J.Bakshi's other question was:

> > ...how can we prevent such emails ?

> The answer is [drumroll]... don't use SMTP e-mail.

> Or alter your receiving SMTP server's filtering rulesets to reject or drop incoming mails not meeting certain technical requirements, including possession of key header lines. Generally, this requires running your own SMTP host (mail tranfer agent) -- rather like A.J. Liebling's dictum that freedom of the press is limited to those who own one.

Thanks to both Rick Moen and Jimmy O'Regan for their explanation. Jimmy's answer is a bonus as he explained through a good practical example. I have just come to know mixmaster. Though haven't gone through its documentation yet, but aptitude show mixmaster shows that it can prevent the recipient knowing your email address.

> [Rick] Er, you might have a use for mixmaster, but the preceding discussion didn't seem to suggest that, and I fear that you might be misunderstanding its intended purpose.

> Mixmaster is a client-server software tool for people running MTAs (SMTP machines), and their users, with the client piece allowing the users to issue pseudonymous e-mails, which the mixmaster daemon (server) piece then remails on their behalf.

> It would be very strange to send your routine, normal outgoing mail through Mixmaster, specifically because it would greatly obscure the identity of the sender. Further, and more to your original point, it would do nothing to prevent you from also receiving spammer-and-malware generated junkmails at your real e-mail address, such as the garbage mail you cited that had a couple of null interior headers.

> As Ben knows, I've long been of the opinion that pretty much all "hide from spammers" strategies (including, well, "preventing the recipient knowing your address") are a dumb idea, really don't work worth a damn, and interfere with legitimate Internet usage to a degree I find unacceptable. At least for those of us who control our own MTAs, there are effective countermeasures, that don't involve self-concealment in any way.

Thanks Rick. You have provided a short as well as good article on Mixmaster & its application ( I may be permitted to say for beginners ). Now I can under stand that as a Workstation owner ( and not an MTA) I don't need Mixmaster. Thanks again.

### Running isoLINUX from a REALLY old machine

R.M.Deal (deal from kzoo.edu)
Question by tag (tag from lists.linuxgazette.net)
Answered By Ben Okopnik

I just read the enlightening article Booting Knoppix from a USB Pendrive via Floppy by Ben Okopnik from the #116 issue of the LINUX gazette.

> [Ben] Well, thank you for the compliment - and I'm glad you enjoyed the article.

I have a similar problem but with an older machine, a Toshiba Satelite Pro 410 CDT, for which I have an external floppy drive. My problem is that the BIOS does not give me the option of booting from a CD. I can boot from either the hard disk or from the floppy.

> [Ben] Have you looked for a BIOS update? I'm not saying that one is definitely available, but if it is, then that would be the simplest solution. Take a look at Toshiba's site and see if there's a download available.

Great suggestion. I shall do that.

Now while I found one article on booting Knoppix from floppies, I wonder if it would be a big deal to modify the script developed by Ben to produce a Knoppix boot, not for a USB pen drive (this portable has NO USB port) but from a floppy. By the way, the Toshiba has installed as an operating system Windows 95 and has only 16 M of RAM so running even KNOPPIX may be a challenge.

> [Ben] The problem is that, shortly after I wrote the article, the information in it became outdated: the next release of Knoppix had a minimum size for the kernel/modules/etc. that was much too large to fit on a floppy. However, for your application, there's an easy answer - or at least used to be (I don't have a Knoppix CD handy to check): just fire up your Wind0ws, look at the Knoppix CD, and there should be a batch file there called "mkfloppy.bat". Run it; after it writes a boot floppy for you, simply reboot, leaving both the floppy and the CD in the machine.

Well, almost. I could not get anything under my Windows boot on the portable (a laptop only if you have strong quadriceps) so I booted my LINUX system (suse 9.3) with KNOPPIX and couldn't find a mkfloppy.bat there.

> [Ben] That wouldn't have helped anyway, since all the commands in the batch file are DOS programs.

Right, but I could not find the batch file from W95 or suse.

However, in a file knoppix-cheatcodes.txt, the procedure to handle floppy boot only is described, using a LINUX command in KNOPPIX named mkbootfloppy. However, when I boot with KNOPPIX, I can find no such file, only a mkboot. That mkboot command looks right but when I run it with an installed blank floppy, after writing on the floppy drive, I get an error message, in German. Now I am living now in Germany (Weimar) and am taking a course in German but I do not have the resources to fully translate technical German.

> [Ben] Whoops... Perhaps you could post that error? My technical German has risen above zero (in part, due to Knoppix , and there are several German-speaking folks here who could help.

OK. Attached is a script of what happened when I tried to produce the boot floppy. It was interesting making the script in KNOPPIX and transferring it to `/mnt/hda2/home/ralph/` after mounting `/mnt/hda2.` Please note that I am working with Knoppix V3.8.1 (2005/04/0 . I am not updating right now because I cannot get DSL in Weimar despite having it in Munich and so am having to use ISDN (hence my switch from Fedora to Suse) in which I can get no flat rate! Once DSL is available ("tomorrow"), I'll update my version.

    Script wurde gestartet: Mo 21 Nov 2005 10:21:56 CET
    root@4[~]# mkboot

    Insert a floppy diskette into your boot drive, and press <Return>.

    Creating a lilo bootdisk...
    cp: Schreiben von ,,/tmp/boot15663/vmlinuz": Auf dem Gerät ist kein Speicherplatz mehr verfügbar
    root@4[~]# exit

    Script beendet: Mo 21 Nov 2005 10:23:11 CET

> [Ben] "No space left on device". At least the version with the umlauts, etc. - "Auf dem Gerät ist kein Speicherplatz mehr verfügbar" - means that. Seems that it's not all that uncommon: searching the Net produces a number of hits. It seems that in some cases, this is produced by bad floppies - but in other cases, it's a result of bad communication with an external floppy drive.

> I'd suggest making the floppy from your Wind0ws, just to see if it works. Having two OSes can be handy for resolving "is it hardware or software?" questions.

I plan on working on deciphering that error message but meanwhile I took the floppy that resulted from that action and tried to boot my portable with it. Unfortunately, it only booted into W95; it seems the boot floppy is faulty. You referred to two floppy disks and so did the cheatcodes.txt file but there was no prompt to put in a second floppy. It may be time for me to contact the programmer of KNOPPIX directly to see what the problem is. I'm guessing that the cheatcodes.txt file was written for an earlier version of KNOPPIX and doesn't describe the procedure correctly for the new version. Did I say LINUX was fun??

> [Ben] Sure. Part of the fun is the ability to make things happen that aren't the norm.

Second, related, question: does anyone recommend a version (old if necessary) of LINUX that would work well as the operating system on the Toshiba?

If these are in some FAQ, I'd appreciate a link.

> [Ben] I find that Puppy Linux (http://www.goosee.com/puppy) works well on older machines, although I haven't done a broad range of experimentation with it; it has a nice desktop and a sufficient range of installed applications that I don't find it restrictive. Other folks here may have other suggestions.

Ain't LINUX fun, Ralph

> [Ben] [grin] Actually, yeah. I like it, m'self.

### Tuppence Tip: URL scraper.

Thomas Adam (thomas from edulinux.homeunix.org)
Question by TAG (tag from lists.linuxgazette.net)

Hello --

This is really an on-going issue from my post regarding urlview and the logging of URLs. I've since decided to take a different approach, and thus far this method works quite nicely. I'm now using 'multi-gnome-terminal' (MGT), 'multitail', 'gmrun', plus a helper script. The overall aim of all of this, was to be able to:

> - Capture URLs from various #channels that I am in (done via irssi already).
> - Open the up in a web browser.

You might wonder what's so hard with this -- the problem is that X11-forwarding on my server takes forever -- it is only a poor P166 with 64MB of RAM, after all. The irssi session resides on the server, so I needed a way of pseudo-opening the URLs as though the request originated on my workstation.

It's unfortunate that I have to use MGT, since it is a memory hog, but needs must. I use it because that has the ability to automatically hotlink URLs -- so that actions can be assigned to it when they're clicked on. Based on this premise, filling in the gaps was easy.

I mount my server's filesystem via 'shfs' -- which I'm now using as a replacement for NFS. I really like it (and a lot less buggy than lufs, and its ilk). This way, I can use multitail to keep an eye on that file. The url logging script that I use from irssi, is "url_log.pl" [1]. All of the logged entries are in the format:

>     Sat 10 Dec 2005 00:57:08 GMT nick #chan URL

... and I wanted multitail to colourise the output, as it does for other files. That was easy -- just create a new colourscheme for it in /etc/multitail.conf:

>     ###URLlog
>     colorscheme:urllog
>     cs_re:green:^... .. ... ....
>     cs_re:magenta:..:..:.. ...
>     cs_re:red:.* \#fvwm (http|https|ftp)://.*$
>     cs_re:blue:.* \#bash (http|https|ftp)://.*$
>     cs_re:cyan:.* \#elinks (http|https|ftp)://.*$
>     cs_re:yellow:.* \#hug (http|https|ftp)://.*$
>     scheme:urllog:/mnt/home/n6tadam/.irssi/urls/url

So to break this down a bit, remember a typical entry from this file will look like:

>     Sat 10 Dec 2005 00:57:08 GMT nick #chan http://myfoo.com

Hence: "Sat 10 Dec 2005" will appear in green. "00:57:08 GMT" in magenta, and the rest of the line will appear in whichever colour is matched by the channel the URL was quoted in. So, it looks pretty.

>     scheme:urllog:/mnt/home/n6tadam/.irssi/urls/url

... should obviously be changed to match whichever file is going to hold the urls from the url_log,pl script.

The next stage was to determine what happens when I clicked on a URL (I say click -- the shortcut to opening a URL via MGT is 'CTRL + middleclick'). I didn't want everything to be sent to my browswer. This is where the "gmrun" utility comes in useful [2]. For those of you that have never used it, it's a very handy, and customisable tool. One of the features it has, is pre-defining prefixes for certain applications. So for instance, I could enter into gmrun:

>     man:bash

... and depending on what I had told gmrun to do with the 'man' prefix, it would open up the bash man page. Neat, eh? So I wanted to have a separate program to open up images, and URLs (it's quite often the case that people post links to screenshots, that I don't want to open in a browser, but would just rather 'see'). I needed to use a helper script to do this, as gmrun accepts no command-line options. The trick I used (in order to make it appear directly in the gmrun window, as though I had typed it), was to append it to gmrun's history file --- if set correctly, gmrun will display the last entered command. No biggie, here it is:

See attached `runvia.sh.txt`

(Saved as ~/bin/runvia.sh -- and chmod 700 ~/bin/runvia.sh)

So, I'm able to flag to gmrun that if the URL I am clicking on is an image, then tell it so, else, flag it to open up in elinks (this is my primary browser -- although I wanted a specific handler for it.) But in order for that script to process the URL that we clicked on from MGT, we need to tell MGT to perform that action. This is easier than you'd think, and involves editing the file: $HOME/.gnome/Gnome, such that:

>     default-show=runvia.sh "%s"

Going back to gmrun, we lastly need to tell it what acrtion to take for the 'elinks:' and 'image:' prefixes. That information is stored in `/etc/gmrunrc`, although I copy this to ~/.gmrunrc, personally, and edit it, so that for the image handler:

>     URL_image = sh -c 'feh %s'

('feh' has the ability to read images via http).

And for the elinks handler:

>     URL_elinks = sh -c '${TermExec} elinks -remote "%s" && FvwmCommand "All (*ELinks*) FlipFocus"'

"${TermExec}" is a variable defined further up in the file that looks like this:

>     Terminal = rxvt
>     TermExec = ${Terminal} +sb -ls -e

... and that's it. It seems to be working really well.

Since I use FVWM, I wanted to (when I had decided to click on a URL) to focus the webbrowser -- hence the reason why I'm using FvwmCommand. This is optional of course. Although to continue on a similar theme, the style of the "gmrun" dialogue window is set to the following:

>     Style Gmrun GrabFocus

.. so that when it pops up, I can hit enter, knowing that the Gmrun window will always have the focus, to execute whatever is inside it.

You can see a screenshot[3] of the url-logger in action.

Hope someone finds this useful, or can derive other ideas from it.

[1] http://www.irssi.org/scripts/html/url_log.pl.html

[2] http://www.bazon.net/mishoo/gmrun.epl

[3] http://edulinux.homeunix.org/~n6tadam/fvwm/ss/url-logger.png

### Global home movies with cron and Imagemagick

Karsten M. Self (karsten from linuxmafia.com)
Question by tag (tag from lists.linuxgazette.net)

I was just showing this to Heather. I've been trying to figure out what's going on with our strange California weather (tropical rainstorms for the past two weeks) and decided that moving satellite images were more interesting than static ones. Among other discoveries, we've been getting a tropical express mainlined to us over the Pacific for the past several weeks, and the movies make this very apparent.

There are two parts to this tip: first, you want to start grabbing satellite images as they're available, then you want to string them together to view them. Updates are 30 minutes and 3 hours for regional and hemispheric views, respectively.

For the fetch, I use cron to schedule downloads, storing them in a large local area, 'data/weather', with a timestamp added to the filename. Recipie, add to your personal crontab:

See attached `crontab.txt`

To animate images, say, from the past five days, you can animate 'find' results. To look at west-coast infraread images:

>     animate -pause 2 -delay 25 $( find . -mtime -5 -name WCIR\*  | sort)

There's some cleanup you may need to do as the download images occasionally get out of order. I've found deleting duplicates seems to fix this pretty readily.

You can also experiment with image enhancements via ImageMagick, such as increasing size and contrast, and reducing noise, in the downloaded images.

This page edited and maintained by the Editors of Linux Gazette
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/

Copyright © 2006, . Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 122 of Linux Gazette, January 2006

<-- prev | next -->