"Linux Gazette...making Linux just a little more lovable!"
More 2¢ Tips!Send Linux Tips and Tricks to [email protected]
Contents:
|
Backquotes Warning
Date: Tue, 14 Jan 1997 00:40:21 -0800
From: alan bailward
In the $0.02 tip for using the script 'swaplogs' the commands :
alan
|
WWW Background Tip
Date: Wed, 8 Jan 1997 12:23:03 -0500 (EST) I noticed people complaining about backgrounds making text unreadable. Personally, I got tired of unreadable backgrounds, as well as large image downloads, so I turned them off. I also turned off those annoying blink tags. How? Add these two lines to your ~/.Xdefaults file.
Netscape*documentColorsHavePriority: False In LG #13, Eje Gustafsson, [email protected] writes: >> 1.mv /var/adm/messages /var/adm/messages.prev >> 2.touch /var/adm/messages >> 3.kill -1 pid-of-syslogd >> >> This should work on a decent Unix(like) system, and I know Linux >>is one of them. > >This is NOT an proper way of truncate /var/adm/messages. > >It is better to do: > > 1.cp /var/adm/messages /var/adm/messages.prev > 2.>/var/adm/messages or cp /dev/null /var/adm/messages (both of them makes >the file empty). > 3.No more.I'm sorry, but (at least on Linux) this is flat out _wrong_. The first method (mv & HUP) is the correct method of truncating syslog files (such as /var/adm/messages). Your method looses any messages that get syslog'd between steps 1 and 2; anything that comes in after the first cp gets overwritten when the second cp happens. >The problem is that when you remove the /var/adm/messages syslogd gets >confused and unhappy and you have to give syslogd a HUPSIG but if you >just sets the file length to zero without removing the file syslogd >don't complain. And if you are really unlucky your system will go down >because you didn't create /var/adm/messages quick enough or forgot it.Not so. mv'ing /var/adm/messages doesn't bother syslogd at all, as long as you stay on the same partition. In fact, you can 'mv /var/adm/messages /var/adm/fish', and until syslogd is HUP'd or otherwise restarted, it will keep logging in the file fish. Try it if you don't believe me - it's true! That is because once syslogd has open()d the file, it will keep writing to that file until it close()s it - and a file in the Unix world is an inode, not a filename. (As an aside, this is how you can have the 100% full empty partition. Even though you unlink or rm a file, the file doesn't actually go away until all programs that have it open close it.) syslogd doesn't get confused at all. You can even rm /var/adm/messages, and syslogd won't crash your system, though eventually the partition may fill up with syslog messages you can't easily read since there isn't a filename associated with the log file anymore.
Kurt Hockenbury, Distributed Systems Administrator
|
Even Better Lowercasing of FilenamesDate: Sun, 5 Jan 1997 19:17:16 -0800 (PST) From: Greg Badros, [email protected] It's even easier with zsh (3.0.x) to convert filenames to all-lowercase: for i in *(.); mv $i ${i:l}The *(.) uses a modifier on the wildcard to mean "only regular files" (i.e., not directories). And the ${i:l} converts the variable to lowercase, so we don't have to use tr. This is not only shorter to type, but doesn't exec multiple programs (test + mv + tr) for each file, and looks at fewer files since the shell implicitly does the first test. Greg
|
Filtering Advertisements from Web Pages using WebFilterDate: Thu, 16 Jan 97 20:28:50 PSTFrom: Axel Boldt, [email protected] Hi, In last month's Gazette, David Rudder wrote an article about how to filter advertisements from web pages using IPFWADM, the idea being that many ads come from the same site and it is easy to configure a Linux firewall to refuse all connections from such a site. This approach has two disadvantages: you have to be root in order to use the IPFWADM tool, and it allows you only to block entire sites. Very often, you want to filter out only a specific ad residing on a site, without blocking the rest of that site's material. Moreover, different users of the Linux box might have different tastes when it comes to ads. I believe that my tool WebFilter a.k.a. NoShit addresses these issues and is better suited for filtering ads from specific web sites. The idea is the following: the user runs WebFilter as a personal filtering proxy server, and the browser contacts this proxy whenever it wants to fetch a web document. The proxy then actually goes out and downloads the page, checks whether any filterscripts apply to this page, and if yes, pipes it through those scripts and returns the output to the browser. The mapping between URL and filterscript has to be provided by the user in advance. A filterscript can be an arbitrary program that reads the original document from standard input and produces the filtered version on standard output. In practice, filterscripts are most often short sed, awk, or perl scripts. If you often use sites such as Yahoo or Infoseek, you can easily write filterscripts that excise the ads from their pages. This saves time, money, and bandwidth. More information about WebFilter can be gotten from its homepage. There you'll also find links to other programs implementing the same idea.
Have fun,
|
Getting less to View gzipped FilesDate: 09 Jan 1997 20:18:58 -0600From: Alan Shutko, [email protected] A little known ability of less is the ability to define filters when it opens and closes files. This excerpt from the man page deserves broader attention, since it can easily be extended to other types. For example, on many Unix systems, these two scripts will allow you to keep files in compressed format, but still let less view them directly: lessopen.sh: #! /bin/sh case "$1" in *.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null if [ -s /tmp/less.$$ ]; then echo /tmp/less.$$ else rm -f /tmp/less.$$ fi ;; Version 321: 18 Jul 96 16 esac lessclose.sh: #! /bin/sh rm $2To use these scripts, put them both where they can be exe- cuted and set Alan Shutko
|
Help for Help on the Bash ShellDate: Tue, 14 Jan 1997 15:36:50 +0100 (NFT)From: mailto:[email protected]
you did hear about help for the bash.
if you invoke
Okay, you know that one.
But did you know you can see all the helps at once?
I did not know it.
Then I tried
So I put everything together and like I do often I created an alias: alias helpall="help '$*' | less -p "and tried it: beautiful, I might not need man bash all the times. Try it yourself.
Perhaps try Have a nice and bright Linux-year! Matthias
|
Lower Your CAPSDate: Sat, 25 Jan 1997 20:44:42 -0800 (PST)From: Peat Bakke, [email protected] One of those little things that gets to me is unzipping DOS pkzipped files. All of the filenames are in all caps. I'm not sure why it bugs me, but it does. Anyhow, here's a quick script that I've found useful to convert all the caps in a directory into lower case (rather nice when you've got one of those big, 200 file zips): #!/bin/tcsh foreach i (*) mv $1 `echo $1 | tr '[A-Z]' '[a-z]'`A word to the wise -- this lowers ALL caps, so be careful with those Makefiles and such. -Peat
|
Making Linux Boot FloppiesDate: Sun, 5 Jan 1997 18:40:49 -0800 (PST)From: Andy Kahn, [email protected] After reading Bill Duncan's excellent article in issue #13 on using and managing floppies in Linux, I figured I'd toss in a 2-cent tip. Here is a script I use to make emergency boot floppies on my system (kernel v2.0.27). The need arose when I installed RedHat 4.0 for the first time and noticed that the installation procedure doesn't automatically prompt you to create boot floppies (Slackware does, and chances are that RedHat will also in the next version).
#!/bin/csh -f # # makebootfloppy v0.2 # # DESCRIPTION: # User friendly script (with lots of verbose messages) used to make # Linux boot floppies, using the 2.x kernels. # # Formats, creates the file system, mounts the floppy, installs the Linux # kernel, installs LILO, umounts floppy, and cleans up. # # (Webmaster's note: Be sure to replace the "^C" in the line below # with a real control-C character! Sorry for the inconvenience ... ) # stty intr ^C set PATH=(/usr/sbin /sbin /bin /usr/bin) # the generic floppy device (usually auto-detected) set GENFLOPPY=/dev/fd0 # the low-level floppy device, used with fdformat. this might be obsoleted # on your system set LLFLOPPY=/dev/fd0H1440 # a temporary mount point for your floppy. make sure it has enough space # to copy the kernel into set MOUNTPOINT=/tmp/floppy # boot set BOOT=/boot/boot.b set KERNEL=/boot/vmlinuz # LILO label set LABEL=linux # here we go! ############# echo -n Insert a blank floppy into the drive and hit return... set FOO=$< # Low-level formatting the floppy... fdformat $LLFLOPPY # Making file system on floppy... mke2fs -c $GENFLOPPY # Mount the floppy mkdir $MOUNTPOINT >& /dev/null mount $GENFLOPPY $MOUNTPOINT # Copy the kernel to the floppy cp $BOOT $MOUNTPOINT cp $KERNEL $MOUNTPOINT # Install lilo echo image=$MOUNTPOINT/`basename $KERNEL` label=$LABEL | \ lilo -C - -b $GENFLOPPY -i $MOUNTPOINT/boot.b -c -m $MOUNTPOINT/map sync # Unmount floppy umount $MOUNTPOINT # Deleting temporary mount point rm -rf $MOUNTPOINT echo All done.
There's currently no error handling, so if one
command fails, the remaining commands will fail as well.
Other than that, feel free to modify and use it as you
like. If you have suggestions on better ways to do
something, I'd love to hear them.
|
More on Xterm Titlebar TipDate: Wed, 15 Jan 1997 23:33:34 -0700 (MST)From: Michael J. Hammel, [email protected] I got a lot of email about my tip, most confused by the use of escape/control characters in the script. Here is my response. > > Date: Sat, 21 Dec 1996 15:18:01 -0600 > > From: Roger BoothI don't think there were transcription problems. I'm pretty sure it was the way I sent it, however.... > > embedded control characters and it was not obvious to me which > > character sequences are representations of control characters > > and which characters should be typed verbatim. Third, theYes, there were control and escape characters in the file. This was a problem and many people wrote me to ask about it. In the following lines: ilabel () { echo -n "^[]1;$*^G"; } label () { echo -n "^[]2;$*^G"; }the characters "^[" are an escape character and the characters "^G" are a CONTROL-G character. In order to add these to your file (when you type it in by hand) using vi you would type:
and
Note that in *this* email I didn't actually include the control or escape characters - I simply used their ASCII equivalents. Hopefully this isn't too confusing. > > author uses a command-line option to the echo command which > > is not available on all Unix platforms.This is also a problem. See below. > > I finally used the following script: > > > > if [ ${SHELL##/*/} = "ksh" ] ; then > > if [[ $TERM = x"term" ]] ; then > > HOSTNAME=`uname -n` > > label () { echo "\\033]2;$*\\007\\c"; } > > alias stripe='label $LOGNAME on $HOSTNAME - ${PWD#$HOME/}' > > cds () { "cd" $*; eval stripe; } > > alias cd=cds > > eval stripe > > fi > > fi > > I don't use vi, so I left out that functionality.I tried this and various similar responses that were mailed directly to me. It should work using the octal versions of the escape sequences, but I couldn't get it to work. My problem is that I use the label() function from the command line at times to simply set the title bar to some arbitrary value and using the octal sequences didn't seem to work for me. I'm not sure why, however. I do believe that, sometime in the distant past, I too used octal sequences to set the xterm title bar. I've long forgotten why I switched. > > The functional changes I made are all in the arguments to the > > echo command. The changes are to use \\033 rather than what > > was shown in the original tip as ^[, to use \\007 rather than > > ^G, and to terminate the string with \\c rather than use the > > option -n.All of these should work just fine in ksh. Your observation that not all shells accept "echo -n" is correct. I often have to check which works and then manually set the echo line to either use "-n" or to print a \c. One or the other will always work, depending on if the echo is a shell builtin or an actual Unix command. > > On AIX 4.1, the command "echo -n hi" echoes "-n hi"; in other > > words, -n is not a portable command-line option to the echo > > command. I tested the above script on AIX 3.2, AIX 4.1, > > HPUX 9.0, HPUX 10.0, Solaris 2.4 and Solaris 2.5. I'm still > > trying to get Linux and my Wintel box mutually configured, > > so I haven't tested it on Linux.I don't use X on the AIX or HPUX boxes at work. I just rlogin from my Sun boxes. However, both Solaris and Linux should work with the -n option if you're using the echo shell builtin. If not, the \c will probably be required. On my Linux box I type bash% type echowhich reports echo is a shell builtinso I know which one I'm using. Knowing this you can provide alternatives within your .bashrc or .kshrc to determine which version of the echo line to use. This is true of any Unix platform on which you use ksh or bash (I believe). > > I have noticed a problem with this script. I use the rlogin > > command to log in to a remote box. When I exit from the > > remote box, the caption is not updated, and still shows the > > hostname and path that was valid just before I exited. I tried > > adding > > > > exits () { "exit" $*; eval stripe; } > > alias exit=exits > > > > and > > > > rlogins () { "rlogin" $*; eval stripe; } > > alias rlogin=rlogins > > > > Neither addition updated the caption to the host/path > > returned to. Any suggestions?Add this right after the alias for cd in the original script: rlogins () { "rlogin" $*; cds . } alias rlogin=rloginsIts a hack, but it works. You have to use "cds" instead of the alias "cd" or else the real cd gets used and the title bar won't change. In case anyone is wondering, the reason you enclose "rlogin" (or "cd" or "vi") in double quotes in this script is so the function rlogins() will run the real rlogin and not get stuck recursively calling itself. Neat, eh?
Boy, this stuff could get confusing fast. Maybe it wasn't such a good tip
after all.
Michael J. Hammel
|
Remind Tip
Date: Mon, 20 Jan 97 15:42:04 PST This is a nice little script wich I have made, it places reminders to ~/.tcshrc or whatever. I think it's very useful. To use it first place at THE END OF ~/.tcshrc: \echo echo "--------------------( R E M I N D E R S )--------------------" echo "-------------------------------------------------------------";\echoThen use this script: ------------------------------c-u-t--h-e-r-e------------------------------- #!/bin/tcsh # Nice little scipt that places reminders to the end of ~/.tcshrc or whatever. # Made by [email protected] email if you like it! echo Remind 1.0 by [email protected] if ($#argv == 0) then echo Use like \'remind \Dont forget to do a 'chmod a+x remind' And NEVER place any new lines after the lines you placed in ~/.tcshrc If you wan't to use it with some other shell it should just be like changing the paths in the script. And yes, it maybe should have been alot easier to put the reminders in a separat file, but i like this solution i'ts alot cooler...and maybe it can show someone how awk works.
|
Script to Call Your EditorDate: Thu, 16 Jan 97 15:21:34 PSTFrom: Gary Chambers, [email protected] I just found the Linux Gazette... Thankfully! It has truly made using Linux more fun. I use the Linux version of Marko Macek's FTE editor. Since it is comprised of a separate X and console version, I began to get frustrated with having to manually specify a default editor. Now, wherever I can specify it (e.g. Pine), I use my edit script. It also provides similar functionality at the command line. I'm new to Linux, so there may be better ways of doing this. I submitted this for inclusion in your 2-cent tips (my favorite section). #!/bin/bash # Determine whether we're in X Windows and call the proper editor # if [ "$WINDOWID" = "" ]; then fte $1 $2 $3 $4 $5 else xfte $1 $2 $3 $4 $5 fiGeeCee, Gary Chambers
|
Tip for Your Web PageDate: Fri, 3 Jan 1997 17:26:14 -0500 (EST)From: Ben Boule, [email protected] One cool tip that I have found useful is the following. If you are running your web page on your own machine or have the directory on NFS, put the following in your .profile :
cp ~/.netscape/bookmarks.html ~/public_html/bookmarks.html Change for different browsers and server setups. Then you can link them on your web page, and they get updated every time you log in, start a new xterm, etc... Of course, this assumes you don't care about other people looking at your bookmarks.
Later,
|
Re: Titlebar TipDate: Mon, 20 Jan 1997 18:40:38 +0200 (SAT)From: Christopher Gordon, [email protected] Roger Booth sent in a corrected version of the Titlebar script. I found that in order to get this working on a Slackware distribution of Linux, using the bash shell, further modifications were neccesary. The control characters need one \ as opposed to \\. The "echo" command required an -e switch. The "if" statement only needed one [] not two. Finally, the script needed to check if "bash" was running or not. I also added a command to simplify the prompt. Here is the corrected script. It can be run using the source command. if [ ${SHELL##/*/} = "bash" ] ; then if [ $TERM = x"term" ] ; then HOSTNAME=`uname -n` label () { echo -e "\033]2;$*\007\c"; } alias stripe='label $LOGNAME on $HOSTNAME - ${PWD#$HOME/}' cds () { "cd" $*; eval stripe; } alias cd=cds eval stripe export PS1='\$ ' fi fiStandard disclaimers apply.
Regards,
|
Two Bit Tip -- HeartbeatDate: Wed, 22 Jan 1997 22:29:06 -0800 (PST)From: Kragen Sittler, [email protected]
|
2 Cent Tip for xdmDate: Sun, 5 Jan 1997 21:28:02 -0600 (CST)From: Andrew Dyer, [email protected] here are several ways you can dress up an xdm login screen:
/usr/X11R6/bin/xv -rmode 1 -nc 64 -quit /home/adyer/pics/arcade.bmp This line will run 'xv' to put the image file at the end of the command line onto the background window in 'root tiled' mode, dithers the image to only use 64 colors (to preserve colormap slots on my 256 color display), and tells xv to exit after doing this. Note that if you run a program like xearth it will continue to run after you have started the session and will contiinue to run by default until the session is exited. See the 'xdm' man page for more details. !!!!!!!!!!!!! !! WARNING !! !!!!!!!!!!!!! programs run by xdm are usually run as root, and so pose a potential security risk if they are not specifically designed for this. You have been warned :-) Andrew M. Dyer
|
Two 2 Cent Tips -- syslog & X Color DepthDate: 13 Jan 1997 10:33:29 +0100From: Marco Melgazzi, [email protected] Dear sirs Here's two 2c tips for your wonderful Linux Gazette. Note that all the lines ending with \ have to be joined on one line. 1. :::: Syslog fun (oh no, not again) ::::: Everybody seem to like to put a line like the following in their syslog: *.* /dev/ttyxthis way every message is printed on an unused tty and the curious ( or worried ) user can switch to it and see what's going on. This approach has a big advantage ( it doesn't use any system resource ) and a couple of disadvantages ( notably you have to switch to text mode to read the messages and then you don't have scrollback ). So I have this little workaround: in /etc/syslog.conf put something like *.* /var/adm/current_session_logIn rc.local or whatever file is called before starting syslog /bin/cat /dev/null > /var/adm/current_session_logIn fvwm you can add something like this: Style "tail" NoTitle, NoHandles, Sticky, WindowListSkip Style "tail" StaysOnTop, CirculateSkip *GoodStuff S-Log telnet-sm.xpm Exec "rxvt" \ rxvt -geometry 132x45-0+0 -sl 1200 -font fixed \ -e tail -n 1200 -f /var/adm/current_session_log &So when you press the goodstuff button named 'S-log' you get a big rxvt with a nice scrollback buffer that displays exactly what's going on in the system. If your linux system stays up for weeks at a time you'll probably have to set up a CRON entry that trims this file every once in a while but this is left as an exercise for the reader ;-) To pop down the rxvt a simple Ctrl-C is more than enough. By the way, this approach will surely save a lot of stress to the monitor electronics: in fact switching from text mode to hires a) takes time b) involves quite a lot of non-trivial adjustments in the monitor circuitry so it could likely acceelerate its ageing process. 2. ::::: How to use X with more than one color depth :::::: I normally use X in 8bit ( since my board is not VRAM based 1152x864 at 70Hz slows down things considerably ) but, since when I hacked my XF86_S3 to let me use higher clocks in 16bit mode :), occasionally I need to switch to the 16bits depth (notably when using the oh-so-amazing 'The Gimp'). Since leaving two servers up and running all the time via xdm seemed a waste of memory, by tinkering with manual pages and articles from the net I came up with a viable alternative. Let me first tell you one thing: in this way, when the second server is running, you get both :0 (in 8bit) that is managed by xdm and :1 that has been started on-demand. Since I don't usually use :1 while I'm online I didn't took the time to provide MIT-MAGIC-COOKIE authorization for it: this is a thing you -should- do if you plan to use this on the net. Here there are a couple of my scripts: ::: ---------------------------------------------------------------- :::/usr/local/bin/1open16 ::: ---------------------------------------------------------------- xinit ~/.x_rc_for_1_16 -- /usr/X11/bin/X16 :1 vt8 & ::: ---------------------------------------------------------------- :::/usr/X11/bin/X16 ::: ---------------------------------------------------------------- #!/bin/sh exec XF86_S3.new -bpp 16 ${@+"$@"} ::: ---------------------------------------------------------------- :::~/.x_rc_for_1_16 ::: ---------------------------------------------------------------- #!/bin/sh # $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $ userresources=$HOME/.Xresources_for_1_16 usermodmap=$HOME/.Xmodmap sysresources=/usr/X11R6/lib/X11/xinit/.Xresources sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap export PATH= .... path .... # merge in defaults and keymaps if [ -f $sysresources ]; then xrdb -merge -display :1 $sysresources & fi if [ -f $sysmodmap ]; then xmodmap -display :1 $sysmodmap & fi if [ -f $userresources ]; then xrdb -merge -display :1 $userresources & fi if [ -f $usermodmap ]; then xmodmap -display :1 $usermodmap & fi .... misc other variables .... exec fvwm -f .fvwmrc_for_1_16 ::: ---------------------------------------------------------------- ::: in ~/.fvwmrc_for_1_16 I have this: I'm not sure this duplication ::: is necessary but in my configuration it is. YMMV ::: ---------------------------------------------------------------- Function "InitFunction" Exec "I" xrdb -display :1 -merge ~/.Xresources & Exec "I" xmodmap -display :1 ~/.Xmodmap & Module "I" GoodStuff Exec "I" emacs & EndFunctionIn this way when you execute the 1open16 script you will get a 16bit screen on :1 at the default resolution you put in your system XF86Config for 16bit depth. Things get a little more hairy if you want to open the new screen with a different set of resolutions: unluckily ( I guess for security reasons ) XFree lets you use a new XF86Config -only- if you are root. So to play Quake on :1 you have to do the following... ::: ---------------------------------------------------------------- ::: in ~/.fvwmrc ( this is nice for password requests, I use it all the ::: time, just put the word 'Password' in the rxvt that you need and use ::: the supplied style. I use it for going online, to access netscape & ::: other net stuff ( I'm paranoid so I created a user named -net- that ::: I use for all internet related stuff, I hate live-data trojans etc.) ::: you get the point.) ::: ---------------------------------------------------------------- Style "*Password" NoTitle, NoHandles, Sticky, WindowListSkip,StaysOnTop ::: in a menu entry Exec "Quake (normal)" exec rxvt -fn \ "-b&h-lucidatypewriter-medium-r-*-*-*-180-75-75-*-*-*-*" \ -geometry 40x1+1-1 -T \"Quake Password" -e \ su root -c "/home/marco/bin/qk" & ::: ---------------------------------------------------------------- ::: /home/marco/bin/qk. The redundant su is needed if you plan to launch ::: this file from the command line too. ::: ---------------------------------------------------------------- cd /home/marco/quake su -c "xinit ./xf86quake -- /usr/X11/bin/X -bpp 8 :1 vt8 -xf86config \ /home/marco/lib/XF86Config.quake"Of course /home/marco/lib/XF86Config.quake will contain only the resolution that I usually play quake at ( that is 400x300 or 512x384 ). In this way you can play quake without hassless even if you usually run at 1000-or-so x 800-or-so at whatever depth. Now if only Linus released the updated 1.06 xf86quake ;-) (in 1.01 you can't use a custom heap, you have the fixed 8mb one :( ). Hope you'll like these tips! Marco Melgazzi
|
X Windows Color DepthDate: Fri, 17 Jan 1997 08:38:20 -0500 (EST)From: Aaron B. Dossett, [email protected] Well, if your video card has enough RAM and you've got enough modes defined in your XF86Config file then you can specify the bit depth from the command line. If you have a link called X to the server then the command X -bpp 8 or X -bpp 16 or X -bpp 24can be used. I like to alias the commands X8, X16, and X24 to the above. For this to work best you should have your XF86Config file setup so that each mode uses the maximum resolution possible. Aaron Dossett, [email protected]
This page maintained by the Editor of Linux Gazette,
[email protected]
|