"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 : cp /var/adm/messages /var/adm/messages.'date +%d' uses the wrong quotes. The backquote not the forward quote has to be used here, to make the *output* of the command part of the filename.

alan

(Actually, the backquote is in the html. It's just that some Browser fonts wont print a backquote -- in fact, mine doesn't. I'm not sure how to get around this other than to warn people who are reading online. If you print LG out, the quotes will be in the right direction. --Editor)


WWW Background Tip

Date: Wed, 8 Jan 1997 12:23:03 -0500 (EST)
From: Kurt M. Hockenbury, [email protected]

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
Netscape*blinkingEnabled: 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
Stevens Institute of Technology


Even Better Lowercasing of Filenames

Date: 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 WebFilter

Date: Thu, 16 Jan 97 20:28:50 PST
From: 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,
Axel


Getting less to View gzipped Files

Date: 09 Jan 1997 20:18:58 -0600
From: 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 $2
To use these scripts, put them both where they can be exe- cuted and set LESSOPEN="lessopen.sh %s", and LESSCLOSE="lessclose.sh %s %s". More complex LESSOPEN and LESSCLOSE scripts may be written to accept other types of compressed files, and so on.

Alan Shutko


Help for Help on the Bash Shell

Date: Tue, 14 Jan 1997 15:36:50 +0100 (NFT)
From: mailto:[email protected]

you did hear about help for the bash. if you invoke help for then you will get some help about for.

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 help "$*" and what happend was: every help was shown! Of course too much for one screen. so I piped it to less: help "$*" |less is quite good. But then I thought about having a search command with less. possible? yes, just do a less -p word file to see it.

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 helpall " let " to see a result.

Have a nice and bright Linux-year!

Matthias


Lower Your CAPS

Date: 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 Floppies

Date: 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.
--Andy, [email protected]


More on Xterm Titlebar Tip

Date: 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 Booth 
> > To: Linux Journal Editor
> > 
> > The Jan97 Issue 33 of Linux Journal contained the "Linux Gazette Two Cent Tips". 
> > I was interested in the tip "X Term Titlebar Function". Although 
> > the text of the tip stated that the tip would work in ksh-based 
> > systems, I could not get it to work as shown. I think there are 
> > three problems. First, I think there are a few transcription 
> > errors in the script. Second, I believe the author is using 
I 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, the 
Yes, 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:

^VESC - which means CTRL-SHIFT-V followed by the ESCAPE key

and

^V^G - which means CTRL-SHIFT-V followed by CTRL-SHIFT-G

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 echo
which reports
 
   echo is a shell builtin 
so 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=rlogins
Its 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
From: [email protected]

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 "-------------------------------------------------------------";\echo
Then 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 \ \\'
echo Option is \'a\' for add , \'u\' for undo and \'r\' for remove, pretty
easy
huh..:\)
\echo
echo NOTE: IF YOU REMOVED A LINE YOU DIDN\'T MEAN TO REMOVE, USE UNDO\!
\echo
exit 666
endif
if ($argv[1] == a) then
cat ~/.tcshrc | awk '\!/-------\";\\echo/ { print }' >! /tmp/remind.$user
echo echo $argv[2-] >> /tmp/remind.$user
echo 'echo "-------------------------------------------------------------";\echo'
>> /tmp/remind.$user
cp ~/.tcshrc ~/.tcshrc.remind
rm -f ~/.tcshrc
mv /tmp/remind.$user ~/.tcshrc
echo Added reminder: $argv[2-]
else if ($argv[1] == r) then
cat ~/.tcshrc | grep -v "echo $argv[2-]" >! /tmp/remind.$user
cp ~/.tcshrc ~/.tcshrc.remind
rm -f ~/.tcshrc
mv /tmp/remind.$user ~/.tcshrc
echo Removed Reminders:
diff ~/.tcshrc ~/.tcshrc.remind | awk '$2 ~ /echo/ { print$3,$4,$5,$6,$7,$8,$9, 
$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25 }'
else if ($argv[1] == u) then
if (-e ~/.tcshrc.remind) then
mv ~/.tcshrc ~/.tcshrc.remtemp
mv ~/.tcshrc.remind ~/.tcshrc
mv ~/.tcshrc.remtemp ~/.tcshrc.remind
echo Undo completed
else
echo No undo file was found \(~/.tcshrc\)
endif
else
echo Error: invalid argument\(s\) run it with no argument for a short help
\echo
exit 666
endif
\echo
---------------------c-u-t--h-e-r-e--a-l-s-o------------------------------
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 Editor

Date: Thu, 16 Jan 97 15:21:34 PST
From: 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
fi
GeeCee, Gary Chambers


Tip for Your Web Page

Date: 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
cp ~/lynx_bookmarks.html ~/public_html/bookmarks2.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,
Ben Boule


Re: Titlebar Tip

Date: 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
     fi           
Standard disclaimers apply.

Regards,
Christopher Gordon,
Remote Sensing, Inst. for Soil, Climate and Water
Pretoria, South Africa


Two Bit Tip -- Heartbeat

Date: Wed, 22 Jan 1997 22:29:06 -0800 (PST)
From: Kragen Sittler, [email protected]
#!/bin/sh # This is a shell archive (produced by GNU sharutils 4.1). # To extract the files from this archive, save it to some FILE, remove # everything before the `!/bin/sh' line above, then type `sh FILE'. # # Made on 1997-01-22 22:11 PST by . # Source directory was `/usr/local/heartbeat'. # # Existing files will *not* be overwritten unless `-c' is specified. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 2222 -rw-r--r-- README # 102 -rw-r--r-- crontab # 371 -rwxr-xr-x heartbeat # 142 -r-xr-xr-x rc.heartbeat # 1045 -rwxr-xr-x update.sessionid # touch -am 1231235999 $$.touch >/dev/null 2>&1 if test ! -f 1231235999 && test -f $$.touch; then shar_touch=touch else shar_touch=: echo echo 'WARNING: not restoring timestamps. Consider getting and' echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 1231235999 $$.touch # # ============= README ============== if test -f 'README' && test X"$1" != X"-c"; then echo 'x - skipping README (file already exists)' else echo 'x - extracting README (text)' sed 's/^X//' << 'SHAR_EOF' > 'README' && Heartbeat package X My computer seems to crash often -- about once every ten days. I've been wanting to know when this happens, but since the computer is busily crashing, it doesn't have time to tell me. (I suspect this happens because of power outages.) X So I wrote a simple heartbeat package, which would keep a record in the filesystem when it was alive. That way, I could look at this record when the machine crashed and tell when and how long it had crashed. X So I wrote a few scripts and created a new user. I named the heartbeat user 'heartbeat'. (I know it's not really kosher to have a nine-letter username, but the only thing that has problems with it so far is ls.) X heartbeat is the first script; it updates a file in /var/log/heartbeat. X Here's the meat of heartbeat. X X #!/bin/sh X touch /var/log/heartbeat/"`cat /var/run/heartbeat.sid`" X /var/log/heartbeat should be writable and executable by the heartbeat user; you may want to use root. heartbeat gets run once a minute on my system, from the heartbeat's crontab: X * * * * * /usr/local/heartbeat/heartbeat X (For some reason, my crond does not like whitespace before crontab entries.) X The name of the file it updates is taken from /var/run/heartbeat.sid. (I'm not sure /var/run is really an appropriate place to put this, but I couldn't find a better place.) This file should be readable and writable by the heartbeat user. X heartbeat.sid is updated at boot time by a Perl script called update.sessionid. update.sessionid also puts some information in the file that heartbeat updates. X I run update.sessionid (as the heartbeat user) from /etc/rc.d/rc.M, just before cron is started. X Here's the section from my rc.M: X X.... # # Update heartbeat sessionid. # This helps us find out when there was a crash. [ -x /etc/rc.d/rc.heartbeat ] && /etc/rc.d/rc.heartbeat X # Start crond (Dillon's crond): X.... X and here's /etc/rc.d/rc.heartbeat: X #!/bin/sh # Update the heartbeat sessionid. # This should be done before starting cron. su heartbeat -c /usr/local/heartbeat/update.sessionid X Now, when I want to know when the machine crashed, I can look in /var/log/heartbeat for the times of system shutdowns -- planned or otherwise. SHAR_EOF $shar_touch -am 0122221197 'README' && chmod 0644 'README' || echo 'restore of README failed' shar_count="`wc -c < 'README'`" test 2222 -eq "$shar_count" || echo "README: original size 2222, current size $shar_count" fi # ============= crontab ============== if test -f 'crontab' && test X"$1" != X"-c"; then echo 'x - skipping crontab (file already exists)' else echo 'x - extracting crontab (text)' sed 's/^X//' << 'SHAR_EOF' > 'crontab' && # MIN HOUR DAY MONTH DAYOFWEEK COMMAND * * * * * /usr/local/heartbeat/heartbeat SHAR_EOF $shar_touch -am 0122221197 'crontab' && chmod 0644 'crontab' || echo 'restore of crontab failed' shar_count="`wc -c < 'crontab'`" test 102 -eq "$shar_count" || echo "crontab: original size 102, current size $shar_count" fi # ============= heartbeat ============== if test -f 'heartbeat' && test X"$1" != X"-c"; then echo 'x - skipping heartbeat (file already exists)' else echo 'x - extracting heartbeat (text)' sed 's/^X//' << 'SHAR_EOF' > 'heartbeat' && #!/bin/sh # script to continually update a file's timestamp, except when the machine # is down # # This should be put in a crontab to be run every minute, or five minutes, # or whatever. # # /var/run/heartbeat.sid contains a sessionid that is incremented at each # bootup, and is suitable for use as a filename. X touch /var/log/heartbeat/"`cat /var/run/heartbeat.sid`" SHAR_EOF $shar_touch -am 0122210097 'heartbeat' && chmod 0755 'heartbeat' || echo 'restore of heartbeat failed' shar_count="`wc -c < 'heartbeat'`" test 371 -eq "$shar_count" || echo "heartbeat: original size 371, current size $shar_count" fi # ============= rc.heartbeat ============== if test -f 'rc.heartbeat' && test X"$1" != X"-c"; then echo 'x - skipping rc.heartbeat (file already exists)' else echo 'x - extracting rc.heartbeat (text)' sed 's/^X//' << 'SHAR_EOF' > 'rc.heartbeat' && #!/bin/sh # Update the heartbeat sessionid. # This should be done before starting cron. su heartbeat -c /usr/local/heartbeat/update.sessionid SHAR_EOF $shar_touch -am 0122221197 'rc.heartbeat' && chmod 0555 'rc.heartbeat' || echo 'restore of rc.heartbeat failed' shar_count="`wc -c < 'rc.heartbeat'`" test 142 -eq "$shar_count" || echo "rc.heartbeat: original size 142, current size $shar_count" fi # ============= update.sessionid ============== if test -f 'update.sessionid' && test X"$1" != X"-c"; then echo 'x - skipping update.sessionid (file already exists)' else echo 'x - extracting update.sessionid (text)' sed 's/^X//' << 'SHAR_EOF' > 'update.sessionid' && #!/usr/bin/perl # Update sessionid for heartbeat, creating new sessionid file. # This should be run at boot time. X my $sessionidfile = "/var/run/heartbeat.sid"; my $heartbeatdir = "/var/log/heartbeat"; X open SESSIONIDFILE, $sessionidfile or X die "Couldn't open <$sessionidfile> for read"; X my $sessionid = ; close SESSIONIDFILE; chomp $sessionid; X if ($sessionid !~ /^[a-zA-Z]*[0-9]{4,}$/) { $sessionid = "boot0000"; } X $sessionid ++; X open SESSIONIDFILE, ">$sessionidfile" or X die "Couldn't open <$sessionidfile> for write"; X print SESSIONIDFILE "$sessionid\n"; close SESSIONIDFILE; X my $heartbeatfile = "$heartbeatdir/$sessionid"; X open HEARTBEATFILE, ">$heartbeatfile" or X die "Couldn't open <$heartbeatfile> for write"; X my $message = < failed after open; fs full? stopped"; X close HEARTBEATFILE; X Xexit 0; SHAR_EOF $shar_touch -am 0122211997 'update.sessionid' && chmod 0755 'update.sessionid' || echo 'restore of update.sessionid failed' shar_count="`wc -c < 'update.sessionid'`" test 1045 -eq "$shar_count" || echo "update.sessionid: original size 1045, current size $shar_count" fi exit 0


2 Cent Tip for xdm

Date: 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:

  1. use the 'Xbanner' program available on sunsite
  2. run a program like xearth or xfishtank that writes to the X login screen background
  3. use a static image display program like 'xv' to put up a simple bitmap
I use xv to put up an image - to do this add a line like the following to the file /usr/X11R6/lib/X11/xdm/Xsetup_0 (at least that's where is is in my system (Caldera)):

/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 Depth

Date: 13 Jan 1997 10:33:29 +0100
From: 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/ttyx
this 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_log
In rc.local or whatever file is called before starting syslog
 
	/bin/cat /dev/null > /var/adm/current_session_log
In 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 &
EndFunction
In 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 Depth

Date: Fri, 17 Jan 1997 08:38:20 -0500 (EST)
From: Aaron B. Dossett, [email protected]
>I have recently been messing with my x-server, and have managed >to get a depth of 16, ie 2^16 colors. This works >really nice with Netscape, but some programs (doom, abuse, and >other games) wont work with this many colors. Do >you know of a fix? I have tried to get X to support multiple >depths--to no avail. The man-page suggests that some >video cards support multiple depths and some don't. How do I know >if mine does.
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 24
can 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]


[ TABLE OF 
CONTENTS ] [ FRONT PAGE ]  Back  Next


This page maintained by the Editor of Linux Gazette, [email protected]
Copyright © 1997 Specialized Systems Consultants, Inc.