old-www/LDP/LG/issue01to08/articles.html

1132 lines
37 KiB
HTML

<HTML>
<!-- BEGIN HTML HEAD ==================================================== -->
<HEAD>
<TITLE>Linux Gazette #8 - Articles</TITLE>
</HEAD>
<!-- END HTML HEAD ====================================================== -->
<!-- BEGIN HTML BODY ==================================================== -->
<BODY>
<H1><IMG ALIGN=MIDDLE SRC="../gx/lg_logo.gif"> Articles!</H1>
<H2>A Member of the Linux Documentation Project</H2>
<H4>&quot;The Linux Gazette...<I>making Linux just a little more fun...!</I>
&quot;</H4>
<H5>Copyright (c) 1996 John M. Fisk <I>fiskjm@ctrvax.vanderbilt.edu</I><BR>
The LINUX GAZETTE is a member of the LINUX DOCUMENTATION PROJECT.<BR></H5>
<HR>
<!-- ==================================================================== -->
<H2>Table of Contents</H2>
<UL>
<LI><A HREF="#awk">An Introduction to AWK, by Cheng Hian Goh</A>
<LI><A HREF="#ansi">Cheap ANSI Color!, by Jim Valentine</A>
<LI><A HREF="#dired">DIRED: Distant Relative of GNU 'ls', by Grant B.
Gustafson</A>
<LI><A HREF="#rm">Securing your RM!, by Christophe Blaess</A>
<LI><A HREF="#tar">TAR'ing over the Net, by Mark A. Bentley</A>
<LI><A HREF="#tcsh">Taking Full Advantage of TCSH - precmd, by Ryan</A>
<LI><A HREF="#xdm">Customizing Logins with XDM, by Yann Le Fablec</A>
<LI><A HREF="#zlister">An Introduction to ZLISTER, by Joe Wulf</A>
</UL>
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="awk">
<CENTER>
<H2>An Introduction to AWK</H2>
by <B>Cheng Hian Goh &lt;chgoh@rombutan.mit.edu&gt;</B>
</CENTER>
</A>
<P>
Enjoyed the LG so much that I decided to contribute my own 2 cents.
<P>
I have always been fascinated by what little languages can do. These
days, we have perl, python, tck/tk and what nots which are so complex
that they can be intimidating some times. One of my favorate was a
little language called &quot;awk&quot;, invented by Aho, Weinberger, and
Kernighan. The gnu implementation is called &quot;gawk&quot; (what
else?).
<P>
I won't go into the syntax of the language, since it can be easily
figured out from the man page (or better still, buy the book &quot;The
AWK Programming Language&quot;). I will however share a few scripts
which I wrote to help me get more productive (or more unproductive?
given that I'm always tweaking them).
<P>
One of the problems which I always had is keeping track of small
details, e.g., a phone number, a URL, and email address, the number of
the combination to the corridor down the hallway. I tried keeping track
of things using &quot;tkpostit&quot; (a postit imitation which runs
under tcl/tk, which is quite nice actually), but the painful thing is
that finding the information I need is not always easy. I keep notes in
different files, which means that I constantly need to figure out which
file is used to keep what. I had this idea that I could just have
pieces of unstructured text written to a file, and retrieve each chunk
based on keywords. So, I created a directory ~/logs under $HOME which
has a file named &quot;.log&quot;. Unstructured text can be entered from
stdin, or the file can be edited using any editor. The only requirement
is that there needs to be a &quot;distinguished&quot; record seperator
(which is *-* in this case). For convenience, I have the simple bash
script in my $HOME/bin, named &quot;addlog&quot; which adds a timestamp
and a record separator.
<PRE>
echo &quot;[&quot;`date`&quot;]&quot; &gt;&gt; ./.log
cat &gt;&gt; ./.log
echo &quot;*-*&quot; &gt;&gt; ./.log
</PRE>
<P>
With this, I could do
<PRE>
bash&gt; addlog
this is a piece of unstructured text about awk
programs and what i can do for me in making more
productive.
^D
bash&gt; _
</PRE>
<P>
I can now do retrieval based on keywords. The actual program is
split into two parts. The first is the bash program which pipes
the log file to an awk program. The second is the awk program itself.
<P>
This is &quot;listlog&quot; which is just a one-liner bash program:
<PRE>
cat ./.log | awk -v pattern=$1 -f ~/bin/searchlog
</PRE>
<P>
&quot;searchlog&quot; is the awk program which does the work:
<PRE>
BEGIN { IGNORECASE=1; RS = &quot;*-*&quot;; nf=split(pattern,array) }
{
hit = 1
for (i=1; i&lt;=nf; i++) {
if ($0 ~ array[i]) ; else hit=0
}
if (hit==1) print
}
</PRE>
<P>
Note that &quot;listlog&quot; and &quot;addlog&quot; needs to be
made executable using &quot;chmod +x &lt;filename&gt;&quot;.
&quot;searchlog&quot; doesn't.
<P>
To retrieve the text fragments in the log file, I just need to
cd to the appropriate directory and do a
<PRE>
bash&gt; listlog &quot;awk text&quot;
</PRE>
<P>
which will return the text I just entered, and whatever other
passages that matches the two keywords. By setting IGNORECASE
to a nonzero value in searchlog, the search is case-insensitive.
This can be changed by removing the statment &quot;IGNORECASE=1;&quot;.
<P>
In the above program, I could have put a fixed path for the log
path which saves me from having to cd to ~/logs each time. However
I wanted to use the same code to add remarks about files I have
in different directories. (After a while, I sometimes couldn't
figure out what a particular file is about, so it is nice to
be able to add a one-liner description to a file). The above
code by default maintain a different .log file in each directory.
so if I want to know what memo.tex is about, I can describe it
by
<PRE>
bash&gt; addlog
memo.tex
this is the memo I sent to boss on
giving me a pay raise.
^D
</PRE>
<P>
I could then do a
<PRE>
listlog &quot;memo.tex&quot;
</PRE>
<P>
to get this description. Alternatively, I could also ask about
pay raise without knowing the filename
<PRE>
listlog &quot;pay raise&quot;
</PRE>
<P>
which will return the same entry. By the way, if there is only
one keyword, then the quotes are not needed. If no keywords are
specified, listlog returns all entries in the logfile.
<P>
I had fun with this. Hope this is useful to someone.
<PRE>
--
+-----------------------------+---------------------------------------+
| Cheng Hian Goh | email: chgoh@mit.edu |
| MIT Sloan School of Mgt | http://rombutan.mit.edu/chgoh.html |
| 50 Memorial Drive E53-320 | Phone: (617)253-2954 |
| Cambridge MA 02139 USA | Fax: (617)258-7579 |
+-----------------------------+---------------------------------------+
</PRE>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="ansi">
<CENTER>
<H2>Cheap ANSI Color!</H2>
by <B>Jim Valentine (simon@tir.com)</B>
</CENTER>
</A>
<P>
Greetings, I'm just another user/self-admin of Linux and I would have to
say that it beats the crap outta anything else I've played with for
OS's. Well, this posting is about creating Cheap Ansi color sequences
using a Very cool text editor called Joe. I came up with this trick out
of pure luck and by rtfm. Well on with the show:
<P>
Joe is a pretty nice text editor that should come with all or most
distributions of Linux. It's easy like pico and powerful like vi,
though I'm sure emacs would blow it away but I've never used emacs
(yet). So, to use this trick you need to use joe.
<P>
Once you start joe it's just a matter of hitting a couple of command
keys. However, you need to know the actual ansi color escape sequences
to do this. The command key is the &quot; ` &quot; key, (reversed
apostrophy), once you do this, joe will ask at the bottom of the screen
what kind of special code you wish to use. Use the left bracet
&quot;[&quot;. It will make a bold text left bracet.
<P>
So by typing: `[[0;31mThis is Red text!`[[1;0m will create red text on
the default background, then return the next instance of text back to
normal.
<P>
I've included some of the color sequence codes here for you to use.
<PRE>
Code Color
-----------------------------
[0;30m | black text
[0;31m | red
[0;32m | green
[0;33m | blue
[0;34m | purple
[0;35m | cyan
[0;36m | silver
[0;40m | red back.
[0;41m | green back.
[0;42m | brown back.
[0;43m | blue back.
[0;44m | purple back.
[0;45m | cyan back.
[0;46m | silver back.
</PRE>
<P>
Ok, now that that is done, here is some explaination of additional codes
you can use to make the colors either bold or blinking.
<P>
0 is for default color.<BR>
1 is for bold (ie. blue becomes light blue)<BR>
5 is for blinking.<BR>
2J will clear the screen.<BR>
<P>
Don't forget to put the small cast 'm' at the end of each code. Also,
once the color has been started, it will stay that way until another
code has been issued. That's why I use the sequence [1;0m to return it
back to the default text color.
<P>
I use color quite often, just to make the system a little more lively.
It can be used in the motd file, or any other file that will be cat'd.
If your terminal doesn't support color then your out of luck.
<P>
Have fun and enjoy.
<P>
Jim Valentine (simon@tir.com)
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="dired">
<CENTER>
<H2>DIRED<BR>
DISTANT RELATIVE of GNU 'LS'</H2>
by Grant B. Gustafson, Univ of Utah<BR>
gustafson@math.utah.edu<BR>
</CENTER>
</A>
<H3>WHAT IS DIRED?</H3>
Suppose you already know color LS. A way to describe DIRED is it is a
cousin of LS with superficial resemblances apparent. DIRED and LS share
listing abilities and colorization. DIRED can take action on the file
names, whereas LS provides information only.
<P>
MIDNIGHT COMMANDER and NORTON COMMANDER. No, DIRED is not one of
these. Not many system administrators use 'commanders', but they would
use LS and DIRED to carry out daily work.
<H3>PHILOSOPHY</H3>
The DIRED philosophy assumes the person at the keyboard already knows
enough unix commands and has no need to learn more. The service of DIRED
is to make it easy to insert file names into unix commands. DIRED could
have been written as a shell script or Perl script, much in the spirit
of the SlackWare programs SETUP and PKGTOOL, but for historic reasons
it's in language C. The design is one big switch statement, each level
of which calls basic functions, similar to the design of Stallman's
emacs. Due to standard design ideas, system programmers immediately
understand DIRED as something they could have written with little effort
(and B E T T E R).
<CENTER>
<H3>DIRED ILLUSTRATED BY EXAMPLE</H3>
</CENTER>
<P>
SOUND EXAMPLE: Find sound files in the /usr tree and listen to the
interesting ones.
<BLOCKQUOTE>
<P>
DIRED is invoked as 'dired /usr'. We know that PLAY is a unix
command that can play most sound files. When a file is found that
looks like a sound file, then invoke the command PLAY on that file.
DIRED allows repeating the last command by pressing PERIOD, so
typing is minimal. The time is spent searching for something
interesting and then listening to the sound.
</BLOCKQUOTE>
<P>
MCOPY EXAMPLE: Find some ZIP archives in the /DOS tree and copy them
to a floppy disk.
<BLOCKQUOTE>
<P>
DIRED is invoked as 'dired /DOS'. When a ZIP file is located, then
press 'm' to invoke the pager LESS, which shows the ZIP file
contents. Those files which are destined for the floppy are tagged
(TAB key) and when enough are found, the whole group is copied to
floppy with the MCOPY command from MTOOLS.
</BLOCKQUOTE>
<P>
FREEUP DISK SPACE EXAMPLE: Find files to delete in /tmp, but archive
them first to a ZIP archive, then delete.
<BLOCKQUOTE>
<P>
DIRED is invoked as 'dired /tmp'. Tag the files (TAB key) to be
archived, then run the unix command ZIP on each file to copy them
all into a ZIP archive. Finally, change all the tags to 'D' and exit
DIRED, whereupon the physical delete occurs.
</BLOCKQUOTE>
<CENTER>
<H3>THREE NORMAL DIRED FUNCTIONS</H3>
</CENTER>
<P>
PRUNING. Files and directories can be tagged 'D' for deletion, the
physical remove taking place all at once, on demand or on exit.
<P>
NAVIGATION. Follow directory trees up and down to see what's there,
using cursor keys and the 'e' or 'E' commands ('e' for EDIT). During
navigation, links and directories are identified. There's a regular
expression search and sorting to make it comfortable. And on-the-fly
screen configuration.
<P>
BROWSE. Looking inside files is passed to the programs LESS and
LESSPIPE.SH, which intelligently view regular files, man pages, rpm
source archives, cpio, tar, zip, tar.z, tar.Z, gzip and compress
archives. There is an internal CAT program for fast viewing of text
and binary files. To fix a file, the system EDITOR is invoked.
<CENTER>
<H3>HOW TO GET DIRED</H3>
</CENTER>
<P>
Get http://sunsite.unc.edu/pub/Linux/utils/file/managers/dired301.tgz
and use the command &quot;cd /; tar -xzf dired301.tgz&quot; to put the
executable and manual page where they belong. A side effect is the
deposit of the sources in /usr/src/dired301 (they can be deleted).
<P>
The currently available version of DIRED is 3.01, June 1996. The
sources are subject to the GNU Public License Agreement (GPL), which
means the whole package is transferred, with source. To compile the
package requires the GNU C compiler and MAKE; there are two source
files, dired.c and regexp.c.
<CENTER>
<H3>LIMITATIONS</H3>
</CENTER>
<P>
Yes, it is limited in scope and features. Any programmer is going to
find something missing. If enough programmers contribute to it, then
either it will grow into a monster or else shrink to the essential
minimum, a migration into maturity that LS enjoys. Since DIRED has
been around since 1980, one would think the maturity is a given. Not
so! Every year someone thinks of a new feature or discovers a new bug.
<PRE>
*-----------------------------------------------------------------*
| Grant B. Gustafson | (801) 581-6879 FAX 581-4148 |
| 113 JWB, Dept Math, U. of Utah | email: gustafso@math.utah.edu |
| Salt Lake City, UT 84112 | URL: http://www.math.utah.edu/ |
*-----------------------------------------------------------------*
</PRE>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="rm">
<CENTER>
<H2>Securing your RM!</H2>
Christophe Blaess &lt;ccb@club-internet.fr&gt;
</CENTER>
</A>
<P>
This is a shell script for Bash, called 'rm_secure'. I use it as
frontal for the rm command. It stores the deleted files in an archive in
the user's directory. A command-line option allows the user to view the
content of this archive, and another option permits the restoration of
the deleted files.
<P>
For example :
<PRE>
$ ls -l
$ ls -l
$ rm --viewtrash
-rw-r--r-- 1 ccb users 22 May 26 10:35 1996 important_file
-rw-r--r-- 1 ccb users 23 May 26 10:35 1996 not_important
$ rm --restore important_file
$ ls -l
-rw-r--r-- 1 ccb users 22 May 26 10:35 important_file
$ rm --viewtrash
-rw-r--r-- 1 ccb users 23 May 26 10:35 1996 not_important
$ rm --emptytrash
$ rm --viewtrash
</PRE>
<P>
Okay, it slows down a few the rm command. But it may also save hours of
work lost due to a keystroke error...
<P>
There is the script 'rm_secure' :
<PRE>
#!/bin/bash
# Configuration
# the real 'rm' command
bin_rm=/bin/rm
# where archiving the files
Archive=~/.rm_saved.tar
# you may prefer something like :
# Archive=/var/trash/$USER/saved_file.tar
# (with write access permission on the directory)
# global variables for the options
Opt_recursive=0
Opt_no_secure=0
Opt_restore=0
Opt_rm=&quot;&quot;
# function for archiving a file or a directory
save_file() {
if [ $Opt_no_secure -ne 1 ] ; then
# set date/time of deletion
touch &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
if [ -f $Archive ] ; then
tar --delete -f &quot;$Archive&quot; &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
tar -rf &quot;$Archive&quot; &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
else
tar -cf &quot;$Archive&quot; &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
# r/w access only for the user
chmod 600 &quot;$Archive&quot;
fi
fi
}
# function for restoring file or directory
restore_file () {
if [ -f $Archive ] ; then
tar -xf &quot;$Archive&quot; &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
tar --delete -f &quot;$Archive&quot; &quot;$1&quot; &gt; /dev/null 2&gt;&amp;1
fi
}
# reading the command-line args
while getopts &quot;dfirRvns-:&quot; opt ; do
case $opt in
d ) Opt_rm=&quot;$Opt_rm -d&quot; ;;
f ) Opt_rm=&quot;$Opt_rm -f&quot; ;;
i ) Opt_rm=&quot;$Opt_rm -i&quot; ;;
r | R ) Opt_recursive=1
Opt_rm=&quot;$Opt_rm -r&quot; ;;
v ) Opt_rm=&quot;$Opt_rm -v&quot; ;;
n ) Opt_no_secure=1 ;;
s ) Option_restore=1 ;;
- ) case $OPTARG in
directory ) Opt_rm=&quot;$Opt_rm -d&quot; ;;
force ) Opt_rm=&quot;$Opt_rm -f&quot; ;;
interactive ) Opt_rm=&quot;$Opt_rm -i&quot; ;;
recursive ) Opt_recursive=1
Opt_rm=&quot;$Opt_rm -r&quot; ;;
help ) $bin_rm --help
echo &quot;(rm_secure)&quot;
echo &quot; -n, --nosecure delete without backup&quot;
echo &quot; --viewtrash list the saved files&quot;
echo &quot; --emptytrash erase the saved files&quot;
echo &quot; -s, --restore restore the specified files&quot;
exit 0 ;;
version ) $bin_rm --version
echo &quot;(rm_secure 1.0)&quot;
exit 0 ;;
verbose ) Opt_rm=&quot;$Opt_rm -v&quot; ;;
viewtrash ) if [ -f $Archive.gz ] ; then
tar -tvzf $Archive.gz
fi
exit 0 ;;
nosecure ) Opt_no_secure=1 ;;
emptytrash ) if [ -f $Archive.gz ] ; then
$bin_rm $Archive.gz
fi
exit 0 ;;
restore ) Opt_restore=1 ;;
* ) ;;
esac ;;
? ) ;;
esac
done
shift $(($OPTIND - 1))
gunzip $Archive.gz &gt; /dev/null 2&gt;&amp;1
# restoration ?
if [ $Opt_restore -ne 0 ] ; then
while [ -n &quot;$1&quot; ] ; do
restore_file &quot;$1&quot;
shift
done
exit 0
else
while [ -n &quot;$1&quot; ] ; do
if [ -d &quot;$1&quot; ] ; then
# the directories are archived only with
# the -r option
if [ $Opt_recursive -ne 0 ] ; then
save_file &quot;$1&quot;
fi
$bin_rm $Opt_rm $1
elif [ -e &quot;$1&quot; ] ; then
# existing file
save_file &quot;$1&quot;
$bin_rm $Opt_rm $1
else
# let 'rm' give his error message
$bin_rm $1
fi
shift
done
fi
nice gzip $Archive &gt; /dev/null 2&gt;&amp;1 &amp;
# -- end of script --
</PRE>
<P>
Place it in /usr/bin or /usr/local/bin then insert a line:
<PRE>
alias rm='/usr/local/bin/rm_secure'
</PRE>
<P>
in /etc/profile, so this script will be called by Bash in the place of
the true rm command.
<P>
You can use the '--nosecure' or '-n' option to delete a file without
archiving it. This is useful when you decide to erase huge amount of
files in recursive directories (for example a package you have tested
but find uninteresting).
<P>
I use a cron job to deleted the archived files every day (running as
root job).
<PRE>
#crontab -l
[ ...]
00 04 * * * /usr/local/bin/empty_trash
#
</PRE>
<P>
Here is the 'empty_trash' script :
<PRE>
#! /bin/bash
for user in /home/* ; do
/bin/rm $user/.rm_saved.tar.gz
done
/bin/rm /root/.rm_saved.tar.gz
# -- end of script --
</PRE>
<P>
Maybe you can prefer something like :
<PRE>
trap '/bin/rm ~/.rm_saved.tar.gz EXIT
</PRE>
<P>
in /etc/profile, which erase the archive each time the user exits
the shell. (I've not fully tested this)
<P>
Obviously this tips doesn't secure the deletion of files or directories
by a file-manager, but I find it quite usefull, especially when doing
administrative jobs as root ('rm tmp/ *' in place of 'rm tmp/*' ...)
<PRE>
____
/ /
Christophe BLAESS / Cabinet
/ Conseil
ccb@club-internet.fr / Blaess
/____/_____
</PRE>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="tar">
<CENTER>
<H2>TAR'ing Over the Net!</H2>
by Mark A. Bentley &lt;bentlema@cs.umn.edu&gt;
</CENTER>
</A>
<P>
Okay, this is useful if it is a pain to mount a remote filesystem via
NFS. I.e. if you don't have root on the machine with the tape drive,
but you do have access to write to the tape device.
<P>
First make sure you can rsh to the machine with the tape drive. You can
test this from the remote machine by executing a simple command like ls.
For example, if your on thufir.cs and you want to see if you have rsh
permissions on caesar, do this at the shell prompt:
<PRE>
thufir% rsh caesar.cs ls
</PRE>
<P>
You should get a directory listing back. If you get &quot;Permission
denied&quot; you have to add the hostname of the remote machine to the
.rhosts file in your home directory on the remote machine. The full
hostname is required, and be careful if your remote machine has multiple
interfaces (i.e. ATM and 10BASE-2). You have to use the hostname that
corisponds the the interface you will be using.
<P>
Anyway, once this is setup, you can use tar, rsh, and dd to dump your
data across the net to a tape device. For example:
<PRE>
thufir% tar cBf - /local-directory | rsh caesar.cs dd of=/dev/tape
</PRE>
<P>
Note: dd will automatically take it's input from stdin if not spcified.
Also, you have to find out the name of the tape device on the remote
machine. For example, on a Solaris machine, it might be /dev/nrst37.
<P>
Also, you can dump any type of data across the net this way. There's
nothing special about tar...
<P>
Have fun...
<PRE>
--
Mark Bentley
Computer Science Systems Staff
University of Minnesota, Twin Cities Campus
</PRE>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="tcsh">
<CENTER>
<H2> Taking full advantage of Tcsh - precmd</H2>
by Ryan &lt;rmrichar@crimson.student.syr.edu&gt;
</CENTER>
</A>
<P>
As an aspiring C programmer, I was strongly attracted to csh when I was
first introduced to UNIX a few short years ago. Since then, I have
found comfort in the tcsh shell, with its superior command-line editing
and history processing. One thing that bothered me about tcsh was the
fact that it doesn't notify you when you have new mail. Bash offers the
MAIL and MAILCHECK enviornment variables (see manual page for bash) to
provide such a system. Here's very simple idea for us tcsh users to try
out.
<P>
Tcsh offers a severly under-rated facility called 'precmd.' This is
actually just a reserved word in the alias facility. By setting an
alias with this name, tcsh will execute the alias before printing each
prompt. Here's an example of this:
<PRE>
crimson:~&gt; alias precmd date
Sat Mar 30 00:46:19 EST 1996
crimson:~&gt; uname -a
Linux crimson 1.2.13 #1 Fri Dec 15 17:55:58 EST 1995 i486
Sat Mar 30 00:46:40 EST 1996
crimson:~&gt;
</PRE>
<P>
This is kind of neat, but what does it have to do with mail? Well, if
we can write a shell script to check for new mail for us, then we can
run it before every prompt is printed. The precmd alias can run
anything. If we wanted to, we could alias precmd to 'netscape &amp;'
and start a copy of that browser everytime a new prompt should be
printed. This would be pointless, and no system in the world has enough
memory to run that many copies of Netscape anyway. :) An obviously silly
example, but it does make a point. Whatever is set up as a precmd
should be as small and sleek as possible.
<P>
So what we need is a sleek shell program to check for new mail and
notify us if we have mail in our queue. By defining the problem, we
have practically already found our solution. Try this on for size:
<PRE>
if ( -e /var/spool/mail/rmrichar )
if ( ! ( -z /var/spool/mail/rmrichar ) )
echo You have mail.
</PRE>
<P>
What is this? Well, you could read this as &quot;if my mail spool
exists, and if it is also not empty, then echo a message to my
screen.&quot; (Refer to the tcsh man page for more information here.)
All we need to do now is alias this so it runs before each prompt is
printed. This can be achieved in the same way that you alias anything,
with one little exception. If you type this in as is, your system will
complain about 'Badly placed (.' All you need to do to overcome this is
wrap our little script in double quotes when you alias it.
<P>
The last step in the process is to generalize our work so we can put it
in our /etc/csh.login file. Remember that this is the file that runs
for all C-shell users on your system as they login. This last step is
also very simple. All we need to do is alter the script and add this a
single line to our csh.login:
<PRE>
alias precmd &quot;if ( -e $MAIL ) if ( ! ( -z $MAIL ) ) echo You have mail.&quot;
</PRE>
<P>
Ta-Dah! We have now seen how to make perfect use of tcsh's precmd alias.
Similar special aliases with all sorts of great uses can be found on the
tcsh man page. Straight from the man page:
<PRE>
cwdcmd the command is run after every change of working
directory.
periodic the command to be run every tperiod minutes.
beepcmd the command to be run every time tcsh wants to
echo the terminal bell.
</PRE>
<P>
Beepcmd is great for Mac and MS-Windows users. By writing an equally
simple bit of shell code, you can play all of your favorite error bells
and whistles as your shell's &quot;system beep&quot;. (See the
Gazette's &quot;Changing that xterm titlebar interactively&quot; for a
great use of cwdcmd. Also see the Gazette's &quot;FVWM and Audio by Nic
Tjirkalli&quot; for more about nifty system sounds.)
<P>
Tcsh has a multitude of useful mechanisms like these. Read the man page
to find out all about completion, prompt formats, history, and even
monitoring logins. Tcsh is a great shell, so have some fun with it!
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="xdm">
<CENTER>
<H2>Customizing Logins with XDM</H2>
by Yann Le Fablec &lt;lefablec@eis.enac.dgac.fr&gt;
</CENTER>
</A>
<H3>
Part 1 : What's xdm and how to install it
</H3>
<P>
Xdm stands for X Display Manager, it provides a graphical login
instead of the usual text one. To install it, first get it (disk
x6/x312cfg.tgz and x7/x312bin.tgz from the Slackware Release 3.0 or in
any sunsite mirrors in the directory X11/xutils/xdm.tar.gz) then compile
it if needed or just follow installation steps. After that, you have to
make it active from the boot sequence :
<UL>
<LI> edit the /etc/inittab file. At the beginning you find a line
like 'id:5:initdefault:', change it to 'id:4:initdefault:'. Number 4
and 5 indicate which runlevel is choosed : 4 means graphical and 5
means text.
<LI> reboot you machine (CTRL-ALT-DEL or sync;reboot)
</UL>
<P>
When booting is finished, you get a graphical login asking your login
and password. If you log in, it's probable that you'll see that your
environment has disappeared : none of your preferences are active as
they used to. Don't worry, we're gonna solve this problem. will setup
what you want.
<H3>
Part 2 : Configuring your login session
</H3>
<P>
There are two ways to do : either you create a .xsession file which will
only be a copy of the '.xinitrc' file, either you change you '.xinitrc'
rights to make it executable. The second method if obviously the
fastest but if you choose the first one, what's important once you've
made the copy is to set it's rights so that it can be executed : type
'chmod o+x .xsession' to have it done. (You have to set these rights
because the '.xinitrc' isn't executable as a default). Your .xsession
should look like this :
<PRE>
-------------------------------------------------------------------------
#!/bin/sh
# $XConsortium: xinitrc.cpp,v 1.4 91/08/22 11:41:34 rws Exp $
userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/usr/X11R6/lib/X11/xinit/.Xresources
sysmodmap=/usr/X11R6/lib/X11/xinit/.Xmodmap
# merge in defaults and keymaps
if [ -f $sysresources ]; then
xrdb -merge $sysresources
fi
if [ -f $sysmodmap ]; then
xmodmap $sysmodmap
fi
if [ -f $userresources ]; then
xrdb -merge $userresources
fi
if [ -f $usermodmap ]; then
xmodmap $usermodmap
fi
# Here starts my environment configuration
# Set the background with the picture sgwbm.jpg
xv -root -rmode 5 -quit /users/yann/Pictures/sgwbm.jpg
# Start a clock in the uppper left corner
/usr/local/bin/emiclock -geometry +0+0&amp;
# Start bowman as my Window Manager
# (could be another one such as fvwm or mwm)
/usr/X11R6/bin/bowman &gt; /users/yann/log
-------------------------------------------------------------------------
</PRE>
<P>
Try it : logout and login again.
<P>
Now you may have noticed that you have a console window on you desktop.
You can get rid of it if you don't like it. In fact it's already present
when the graphical login starts so you can guess that it is started in
one of xdm configuration files. Theses files are located in
/usr/X11R6/lib/X11/xdm/ so cd to that directory.
<P>
Note that in order to modify any file in this directory you need to be root.
<P>
You can launch new programs in the 'Xsetup_0' file so make a copy before
modifying it. Edit it, it looks like this :
<PRE>
#!/bin/sh
# $XConsortium: Xsetup_0,v 1.3 93/09/28 14:30:31 gildea Exp $
xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
</PRE>
<P>
You can see that the console window is started here so comment it (with
a #) to get rid of it. What you can do now is add some new lines to
change the background or start a clock for example. My 'Xsetup_0' is :
<PRE>
#!/bin/sh
# $XConsortium: Xsetup_0,v 1.3 93/09/28 14:30:31 gildea Exp $
#xconsole -geometry 480x130-0-0 -daemon -notify -verbose -fn fixed -exitOnFail
# Change background to display a picture
xv -root -rmode 5 -quit /users/yann/Pictures/somtrace.gif
# Start a clock above the login window
xclock -digital -update 1 -geometry +530+100 &amp;
# Start the xsnow program (why not ?)
xsnow &gt; /dev/null &amp;
</PRE>
<P>
If you try it, you'll discover that once you're logged in, the xclock
and xsnow programs are still running so you may want to stop them before
in order not to have to kill them by hand each time you log in. You can
do that by modifying the GiveConsole script because it's executed after
you typed your password and before your environment comes up. By default
it contains :
<PRE>
#!/bin/sh
# Assign ownership of the console to the invoking user
# $XConsortium: GiveConsole,v 1.2 93/09/28 14:29:20 gildea Exp $
#
# By convention, both xconsole and xterm -C check that the
# console is owned by the invoking user and is readable before attaching
# the console output. This way a random user can invoke xterm -C without
# causing serious grief.
#
chown $USER /dev/console
In our case, we want to kill the xclock and xsnow processes, so we should modify it like this :
#!/bin/sh
# Assign ownership of the console to the invoking user
# $XConsortium: GiveConsole,v 1.2 93/09/28 14:29:20 gildea Exp $
#
# By convention, both xconsole and xterm -C check that the
# console is owned by the invoking user and is readable before attaching
# the console output. This way a random user can invoke xterm -C without
# causing serious grief.
#
chown $USER /dev/console
# Get list of processes related to xclock (xclock itself and the grep command)
processes=`ps -x | grep &quot;xclock&quot; | awk '{print $1}'`
# Get first id in this list : it corresponds to xclock
id=`echo $processes | awk '{print $1}'
# Kill the process
kill -9 $id &gt; /dev/null
# Do the same thing for xsnow
processes=`ps -x | grep &quot;xsnow&quot; | awk '{print $1}'`
id=`echo $processes | awk '{print $1}'`
kill -9 $id &gt; /dev/null
</PRE>
<P>
I know it's a bit brutal to do it that way so if you have better ideas
let me know.
<P>
Ok, now you've configured your graphical login sequence so enjoy !
<PRE>
===============================================================================
Yann Le Fablec
Ecole Nationale de l'Aviation Civile
Tel : 62.17.41.59
E-mail : lefablec@eis.enac.dgac.fr
http : http://www.eis.enac.dgac.fr:8001/~lefablec/Welcome.html
===============================================================================
</PRE>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<A NAME="zlister">
<CENTER>
<H2>Announcing ZLISTER</H2>
by Joe Wulf &lt;swulf@infi.net&gt;
</CENTER>
</A>
<P>
(Joe and I have been exchanging email for a bit now and he asked if I'd be
willing to include this LSM description of his <I>zlister</I> program --
something that I was quite happy to do. In addition, he's made a copy of
this program available so that you can pick up a copy of it using the link
at the end of the LSM form. Have fun with this and let me know what you
think! -- John)
<PRE>
Begin3
Title: zlister
Version: 1.4
Entered-date: 18MAY96 @ 17:50 EDT
Description: Combination of csh and awk scripts designed to manage the
collection, compression, differentiation and storage of
complete filesystem listings. It is an administrative support
tool that will identify changes to any file in the filesystem.
When executed on a frequent basis (i.e. daily), the resulting
.diff output can provide invaluable clues to system/security
administrative personnel as to EVERY file which changes on the
system listed. In conjunction with frequent (daily) system
backups, the potential for any form of data loss can be
significantly reduced. Of course, the benefits will be
maximized with appropriate attention to the output. This is
an ideal product to execute on newly built and/or rebuilt
production servers to get/establish/document the baseline of
the complete filesystem. Subsequent runs will highlight
differences. Especially benificial to be ran after a
filesystem check (fsck) has been run and significant errors
were reported/corrected. Copious documentation and
installation instructions are provided in the primary
'zlister' script. These scripts were designed to execute,
without modification, on Solaris (V: 2.3, 2.4 and 2.5), HP-UX
(V: 9.0.01 - 10.0) and under all versions of Linux
(V: 1.1.59+).
I'm very interested in feedback from implementator(s) on
other *NIX platforms. Unfortunately, my internet email
address will cease to exist after 96 Jun 30. At that time I
will only have snail mail available to me :( at:
DP1 Joe Wulf
USNS Spica (T-AFS 9)
FPO AP 96678-4066
I'm looking for people willing to help me manage this project
and edit the scripts to get them to work on their platform.
If you are interested in doing this, please write me and let
me know what plaform (and version of unix).
Keywords: filesystem ls ls-laR admin tool csh awk scripts
Author: swulf@infi.net (Joe Wulf) # Only until 960730
huntj@wangfed.com (Jim Hunt) # Alternate Point of Contact.
Primary-site: sunsite.unc.edu:/pub/Linux/system/admin
66K zlister.taz
3K zlister.lsm
Alternate-site:
Original-site:
Platforms: Currently functions with out modification on Solaris, HP
and Linux boxes; will funtion on other *NIX's with only
minor modifications (fully explained in the scripts).
Copying-policy: GPL
</PRE>
<P>
<H3><A HREF="./misc/zlister.tar.gz">Get a copy of zlister</A></H3>
<!-- ==================================================================== -->
<P><HR><P>
<!-- ==================================================================== -->
<P> Well, thanks SO very much again to everyone that wrote and submitted
articles. There is just NO way that the 'ol LG could continue without
all of the ongoing encouragement, support, and hard work by so many
folks.
<P>
Hope you Enjoyed!
<P>
John
<H3><A HREF="./lg_issue8.html">Back to Linux Gazette #8</A></H3>
</BODY>
</HTML>