...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


Firewall

Hugo Mills (darksatanic, #hants on irc.blitzed.org)
13:04 <@darksatanic> I usually use it for debugging firewalls.
13:04 <@darksatanic> watch -n1 iptables -nvL \| sed -ne /^Chain INPUT/,/^$/p
13:05 <@darksatanic> There's a 2¢ tip for you...
13:07 <@darksatanic> The sed bit prints out just the chain you want.
13:08 <@darksatanic> My rules for the firewall are just a tad too big to fit on the screen,
13:09 <@darksatanic> so I use that (and things like it) to show only the chains I want.



Cygwin from a CD

Jimmy O'Regan (The LG Answer Gang)
(!) [Jimmy] This is a follow-up to http://linuxgazette.net/109/lg_tips.html#tips.2

Whoops. Having just looked back over the .reg file, I see that I have the path for X's fonts entered differently to the rest of the file: this /is not/ the reason why X doesn't work from a CD.

Saw this on Slashdot today: XliveCD (http://xlivecd.indiana.edu) is a CD image that autoruns an X session when put into a Windows machine (it's based on Cygwin).


Tip of the Day: regular expressions

Dave Whitinger (dave from lxer.com)

Forwarding to you a good tip by Robert Whitinger. If you ever run dry and need fresh tips for upcoming LGs let me know - we've got a ton of these fun ones.

[Ben] Thanks, Dave - we're always looking for 2-cent tips like these! I believe Heather has mentioned this in the Mailbag recently.

(And please keep up the great work!)

[Ben] [grin] Much appreciated; we'll do our best. Keep on reading, and let your friends know about us; the more folks read (and write for) us, the better we get.

best, dave

...............

I don't know about you, but I've spent a lot of time learning all the intricacies of the preg_... pcre functions. But whenever I go to the shell environment, the rules are different and so are the results.

Today, I found `pcregrep` and it behaves exactly like the perl compatible regular expression from php and perl since it does in fact use the same engine. Now I have only one regex syntax to know in detail, and my regexs work the same everywhere.

Now, I can say things like:

pcregrep -r ^[ae].*?log$ *

...............


Adding custom headers in Thunderbird

Andy Burns (andy.burns from adslpipe.co.uk)
Answered By Brian Bilbrey, Jimmy O'Regan
(!) [Jimmy] This is a follow-up to a 2c Tip in LG #109: http://linuxgazette.net/109/lg_tips.html#tips.1

I stumbled across your article on mozilla/thunderbird headers (I'm only an irregular reader)

I had a look an the "mheny" extension, because I like the idea of customising the viewed headers, but I found that it CAN also control the headers used at composition time. Not sure if you "summarized this out" of your article, or didn't find it to start with ;-)

Within the option dialog for mheny extension, select custom headers from the tree on the left, then pick composition from the drop list on the right, and you can select existing fields or add/remove custom fields, which then show up when you compose a message.

However (and I think this means it still doesn't fit your need) you can't add a default value for a field.

[Brian] And that's the bingo value: I did try mnenhy, but what I really want is a constant X-blah header containing a specific value every time I send an email via Mozilla Thunderbird.

Still a useful find, thanks ...

[Brian] But you got farther than I did, thanks for the heads up, I'll work some more with mnenhy when I get a chance. Of course, that I just spelled the name of the extension right twice only shows that I had to look it up twice, inside of a minute or two.
[Jimmy] I came across this: http://www.picklematrix.net/archives/000969.html it turns out it /is/ possible to add values to headers in Mozilla
add something like this to your prefs.js (not user.js):
user_pref("mail.identity.id2.headers", "tag");
user_pref("mail.identity.id2.header.tag", "X-gazette-tag: Jimmy");
(id1 is the 'local folders' identity)


Counting braces

Amod C Damle (amod_cd from rediffmail.com)

i am learning from your website "Linux Gazette" by which i am finding it easy to learn unix.

but i am having problems compiling and debugging the following program ... can you please help me out with its solution.

using UNIX filters and awk to write a shell script to filter out comment statements in a C program

a shell script to count the number of parentheses and braces in a C program

a shell script to recognize function calls in a C program

a shell script to generate code to do profiling of a C program (to insert counters to the C program)

using filter or just grep, sed and awk)

hoping for some guidence sincerely Amod Damle (ILLINOIS INSTITUTE OF TECHNOLOGY-CHICAGO)

[Sluggo] The first thing you should see is the TAG Posting Guidelines http://linuxgazette.net/tag/ask-the-gang.html in the FAQ section. There you'll see we don't do people's homework for them. How do we know it's homework? You don't want to do a useful task: who cares how many braces a C program has? You choose the tools first and then the strategy, and you insist on using kludgey tools. If I really wanted to count braces, I would write a Python program.
#!/usr/bin/env python
"""count-braces.py

Usage: count-braces.py <filename
Print the number of {}() characters in the input file.
"""
import re, sys

braceRx = re.compile( R"[{}()]" )
text = sys.stdin.read()
hits = braceRx.findall(text)
print len(hits)
[Ben] Jeez. Pythoneers. Always making things more complicated. :)
perl -0wne'print y/{()}//' file.c


JPEG to PS

Kapil Hari Paranjape (The LG Answer Gang)

Readers who wish to convert JPEG to Postscript for inclusion in a TeX/LaTeX document (or for any other reason) may want to use:

	convert file.jpg eps2:file.eps
	                    ^

Note the 2! This is better than the default "convert file.jpg file.eps" and performs the same function as "jpeg2ps" (which is in Debian non-free).

Explanation: The default postscript level for PS conversion is 1 which produces large and bad conversions since it produces pixelised bitmaps. In PS Level 2 and Level 3 the conversion of JPEG is inbuilt so the above procedure just adds a bit of postscript header stuff to the unchanged jpeg file. In other words this conversion is lossless.

You can also use "eps3" as the tag but beware that may be reasonably new postscript printers that are not level 3 compliant. (Ghostscript is level 3 compliant).


Setting the Clock on Linux

Walt R (wmreinemer from tns.net)
(!) [Jimmy] This is a follow-up to http://linuxgazette.net/109/lg_mail.html#mailbag.1

The following script is my interface to netdate. I modified the script found at website listed in the script. You have to be root to set the system and hardware clocks, yet you can query the time servers as a regular user.

Walt Reinemer

See attached netdate.sh.txt


SMTP-time despamming

Ben Okopnik (LG Editor)

Just saw this at Freshmeat; sounds really sweet, particularly the per-user configuration capability. Hopefully, the world is heading this way...

...............

 Mail Avenger 0.5.1
 by xxx - Sun, Nov 21st 2004 02:48 PDT

About: Mail Avenger is a highly-configurable, MTA-independent SMTP server. It allows you to reject spam during mail transactions, before spooling messages in your local mail queue. You can specify site-wide default policies for filtering mail, but individual users can also craft their own policies by creating avenger scripts in their home directories. It includes many features not supported by other SMTP servers, including mail-bomb protection, integration with kernel firewalls, TCP SYN fingerprint and network route recording, SMTP-level analysis of client implementations, SMTP callbacks to verify sender addresses, per-user mail scripts that run during SMTP transactions, virtual domain to user mapping for the purposes of filtering, SPF (sender policy framework), dynamic SPF query construction in mail filter scripts, support for easily issuing multiple concurrent, asynchronous DNS and SPF queries from filter scripts, and the ability to run spam filters such as spamassassin on message bodies before replying to SMTP DATA commands.

Changes: A critical memory handling bug was fixed in the avenger.local and deliver utilities.

...............


starting X automatically without [gkx]dm

Ben (LG Editor)

As past discussions in TAG have shown, I'm definitely not a fan of the various display managers; I believe that they take away, or obscure, too much of the control that a user has over X. However, starting X automatically from your ~/.bash_profile doesn't seem like a very smart move either: any time you get a login shell (e.g., logging into another console), you'd be firing off a new instance of X - or at least trying to, since it would die with a list of error messages.

The answer to this dilemma is a conditional start for X - in other words, we only want to execute it if it's not already running, i.e. only on the first login. To do this, just add the following line to the end of your ~/.bash_profile:

ps ax|grep -q "[ ]`which X`" || startx

For those who just have to know ([grin] I certainly would, if I were you): the above expression pipes the list of running processes, which is the output of the "ps" command, to 'grep', which searches it for the presence of a running X. To make the search more precise, the command substitution (`which X`) returns the full pathname to X as the search string. The character class preceding the search string ([ ]) is there to make 'grep' ignore its own entry in process table (an old 'grep' trick), and the "-q" option of 'grep' makes it return only a success/failure exit code instead of the actual matched string. The OR operator, '||', ties it all together into an expression that says "either X is running OR (execute) startx".


whois.sc

Jared Belkus (jared.belkus from gmail.com)

hi,

i was told to email this address about a useful website:

http://www.whois.sc

I use this whois website a lot because of the information it gives. If you sign up you can see all the domains that a server has.

thanks,
Jared Belkus

Just in case you're a sysadmin thinking, geez, just how many sites am I running on this machine again... did I miss any during that upgrade... -- Heather

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 © 2005, . Released under the Open Publication license

Published in Issue 110 of Linux Gazette, January 2005

<-- prev | next -->
Tux