home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / TIPS-HOW < prev    next >
Text File  |  1999-11-04  |  37KB  |  1,189 lines

  1.   The Linux Tips HOWTO
  2.   Paul Anderson, paul@geeky1.ebtech.net
  3.   v3.6, June 1998
  4.  
  5.   This HOWTO contains those hard to find hints and tweekings that make
  6.   Linux a bit nicer.
  7.   ______________________________________________________________________
  8.  
  9.   Table of Contents
  10.  
  11.  
  12.   1. Introduction
  13.  
  14.   2. Short Tips
  15.  
  16.      2.1 Handy Syslog Trick
  17.      2.2 Script to view those compressed HOWTOs.
  18.      2.3 Is there enough free space???
  19.      2.4 Util to clean up your logfiles.
  20.      2.5 Handy Script to Clean Up Corefiles.
  21.      2.6 Moving directories between filesystems.
  22.      2.7 Finding out which directories are the largest.
  23.      2.8 The Linux Gazette
  24.      2.9 Pointer to patch for GNU Make 3.70 to change VPATH behavior.
  25.      2.10 How do I stop my system from fscking on each reboot?
  26.      2.11 How to avoid fscks caused by "device busy" at reboot time.
  27.      2.12 How to find the biggest files on your hard-drive.
  28.      2.13 How to print pages with a margin for hole punching.
  29.      2.14 A way to search through trees of files for a particular regular expression.
  30.      2.15 A script for cleaning up after programs that create autosave and backup files.
  31.      2.16 How to find out what process is eating the most memory.
  32.      2.17 Rigging vi for C programming,
  33.      2.18 Using ctags to ease programming.
  34.      2.19 Why does sendmail hang for 5 minutes on startup with RedHat?
  35.      2.20 How do I configure RedHat for using color-ls?
  36.      2.21 How do I find which library in /usr/lib holds a certain function?
  37.      2.22 I compiled a small test program in C, but when I run it, I get no output!
  38.  
  39.   3. Detailed Tips
  40.  
  41.      3.1 Sharing swap partitions between Linux and Windows.
  42.      3.2 Desperate Undelete.
  43.      3.3 How to use the immutable flag.
  44.      3.4 A suggestion for where to put new stuff.
  45.      3.5 Converting all files in a directory to lowercase.
  46.      3.6 How To Upgrade Sendmail
  47.      3.7 Some tips for new sysadmins.
  48.      3.8 How to configure xdm's chooser for host selection.
  49.  
  50.  
  51.   ______________________________________________________________________
  52.  
  53.   1.  Introduction
  54.  
  55.   Welcome to the Linux Tips HOWTO, a list of neato tricks and
  56.   optimizations that make Linux more fun.  All I have in here right now
  57.   are tips off of the top of my head, and tips from the old Tips-HOWTO
  58.   (Why take out decent tips, right?).  So send all your favorite hints
  59.   and tips to me so I can put them in the next Tips-HOWTO.
  60.  
  61.   Paul Anderson Maintainer--Linux TIPS HOWTO
  62.  
  63.   panderso@ebtech.net
  64.  
  65.  
  66.  
  67.   2.  Short Tips
  68.  
  69.   2.1.  Handy Syslog Trick Paul Anderson, Tips-HOWTO maintainer
  70.  
  71.   Edit your /etc/syslog.conf, and put in the following line:
  72.  
  73.  
  74.        # Dump everything on tty8
  75.        *.*                                     /dev/tty8
  76.  
  77.  
  78.  
  79.  
  80.   One caveat: REMEMBER TO USE TABS!  syslog doesn't like spaces...
  81.  
  82.  
  83.   2.2.  Script to view those compressed HOWTOs. Didier Juges,  dj@des¡
  84.   tin.nfds.net
  85.  
  86.  
  87.   From a newbie to another, here is a short script that eases looking
  88.   for and viewing howto documents.  My howto's are in
  89.   /usr/doc/faq/howto/ and are gzipped. The file names are XXX-HOWTO.gz,
  90.   XXX being the subject.  I created the following script called "howto"
  91.   in the /usr/local/sbin directory:
  92.  
  93.  
  94.        ______________________________________________________________________
  95.        #!/bin/sh
  96.        if [ "$1" = "" ]; then
  97.            ls /usr/doc/faq/howto | less
  98.        else
  99.            gunzip -c /usr/doc/faq/howto/$1-HOWTO.gz | less
  100.        fi
  101.        ______________________________________________________________________
  102.  
  103.  
  104.  
  105.  
  106.   When called without argument, it displays a directory of the available
  107.   howto's. Then when entered with the first part of the file name
  108.   (before the hyphen) as an argument, it unzips (keeping the original
  109.   intact) then displays the document.
  110.  
  111.   For instance, to view the Serial-HOWTO.gz document, enter:
  112.  
  113.   $ howto Serial
  114.  
  115.  
  116.  
  117.   2.3.  Is there enough free space??? Hans Zoebelein,  zocki@gold¡
  118.   fish.cube.net
  119.  
  120.   Here comes a short script which will check from time to time that
  121.   there is enough free space available on anything which shows up in
  122.   mount (disks, cdrom, floppy...)
  123.  
  124.   If space runs out, a message is printed every X seconds to the screen
  125.   and 1 mail message per filled device is fired up.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.   ______________________________________________________________________
  134.   #!/bin/sh
  135.  
  136.   #
  137.   # $Id: check_hdspace,v 1.18 1996/12/11 22:33:29 root Exp root $
  138.   #
  139.  
  140.   #
  141.   # Since I got mysterious error messages during compile when
  142.   # tmp files filled up my disks, I wrote this to get a warning
  143.   # before disks are full.
  144.   #
  145.   # If this stuff saved your servers from exploding,
  146.   # send praising email to zocki@goldfish.cube.net.
  147.   # If your site burns down because of this, sorry but I
  148.   # warned you: no comps.
  149.   # If you really know how to handle sed, please forgive me :)
  150.   #
  151.  
  152.   #
  153.   # Shoot and forget: Put 'check_hdspace &' in rc.local.
  154.   # Checks for free space on devices every $SLEEPTIME sec.
  155.   # You even might check your floppies or tape drives. :)
  156.   # If free space is below $MINFREE (kb), it will echo a warning
  157.   # and send one mail for each triggering device to $MAIL_TO_ME.
  158.   # If there is more free space than trigger limit again,
  159.   # mail action is also armed again.
  160.   #
  161.  
  162.   # TODO: Different $MINFREE for each device.
  163.   # Free /*tmp dirs securely from old junk stuff if no more free space.
  164.  
  165.  
  166.   DEVICES='/dev/sda2 /dev/sda8 /dev/sda9'         # device; your put disks here
  167.   MINFREE=20480                                   # kb; below this do warning
  168.   SLEEPTIME=10                                    # sec; sleep between checks
  169.   MAIL_TO_ME='root@localhost'                     # fool; to whom mail warning
  170.  
  171.  
  172.   # ------- no changes needed below this line (hopefully :) -------
  173.  
  174.   MINMB=0
  175.   ISFREE=0
  176.   MAILED=""
  177.   let MINMB=$MINFREE/1024         # yep, we are strict :)
  178.  
  179.   while [ 1 ]; do
  180.           DF="`/bin/df`"
  181.                   for DEVICE in $DEVICES ; do
  182.                   ISFREE=`echo $DF | sed s#.\*$DEVICE" "\*[0-9]\*""\*[0-9]\*" "\*## | sed s#" ".\*##`
  183.  
  184.                   if [ $ISFREE -le $MINFREE ] ; then
  185.                           let ISMB=$ISFREE/1024
  186.                           echo  "WARNING: $DEVICE only $ISMB mb free." >&2
  187.                           #echo "more stuff here" >&2
  188.                           echo -e "\a\a\a\a"
  189.  
  190.                           if [ -z  "`echo $MAILED | grep -w $DEVICE`" ] ; then
  191.                                   echo "WARNING: $DEVICE only $ISMB mb free.      (Trigger is set to $MINMB mb)" \
  192.                                   | mail -s "WARNING: $DEVICE only $ISMB mb free!" $MAIL_TO_ME
  193.                                   MAILEDH="$MAILED $DEVICE"
  194.                                   MAILED=$MAILEDH
  195.                                   # put further action here like cleaning
  196.                                   # up */tmp dirs...
  197.                           fi
  198.                           elif [ -n  "`echo $MAILED | grep -w $DEVICE`" ] ; then
  199.                                   # Remove mailed marker if enough disk space
  200.                                   # again. So we are ready for new mailing action.
  201.                                   MAILEDH="`echo $MAILED  | sed s#$DEVICE##`"
  202.                                   MAILED=$MAILEDH
  203.                           fi
  204.  
  205.                   done
  206.                   sleep $SLEEPTIME
  207.  
  208.   done
  209.   ______________________________________________________________________
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.   2.4.  Util to clean up your logfiles. Paul Anderson, Tips-HOWTO Main¡
  217.   tainer >
  218.  
  219.   If you're like me, you have a list with 430 subscribers, plus 100+
  220.   messages per day coming in over UUCP.  Well, what's a hacker to do
  221.   with these huge logs?  Install chklogs, that's what.  Chklogs is
  222.   written by Emilio Grimaldo, grimaldo@panama.iaehv.nl, and the current
  223.   version 1.8 available from
  224.   ftp.iaehv.nl:/pub/users/grimaldo/chklogs-1.8.tar.gz.  It's pretty self
  225.   explanatory to install(you will, of course, check out the info in the
  226.   doc subdirectory).  Once you've got it installed, add a crontab entry
  227.   like this:
  228.  
  229.  
  230.        # Run chklogs at 9:00PM daily.
  231.        00 21 * * *       /usr/local/sbin/chklogs -m
  232.  
  233.  
  234.  
  235.  
  236.   While you're at it, mention to the author how nice a peice of software
  237.   this is:)
  238.  
  239.  
  240.  
  241.   2.5.  ohammers@cu-online.com Handy Script to Clean Up Corefiles. Otto
  242.   Hammersmith,
  243.  
  244.   Create a file called rmcores(the author calls it handle-cores) with
  245.   the following in it:
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.   ______________________________________________________________________
  266.   #!/bin/sh
  267.   USAGE="$0 <directory> <message-file>"
  268.  
  269.   if [ $# != 2 ] ; then
  270.           echo $USAGE
  271.           exit
  272.   fi
  273.  
  274.    echo Deleting...
  275.   find $1 -name core -atime 7 -print -type f -exec rm {} \;
  276.  
  277.   echo e-mailing
  278.   for name in `find $1 -name core -exec ls -l {} \; | cut -c16-24`
  279.   do
  280.           echo $name
  281.           cat $2 | mail $name
  282.   done
  283.   ______________________________________________________________________
  284.  
  285.  
  286.  
  287.  
  288.   And have a cron job run it every so often.
  289.  
  290.  
  291.  
  292.   2.6.  Moving directories between filesystems. Alan Cox,
  293.   A.Cox@swansea.ac.uk
  294.  
  295.   Quick way to move an entire tree of files from one disk to another
  296.  
  297.  
  298.        (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)
  299.  
  300.  
  301.  
  302.  
  303.   [ Change from cd /source/directory; tar....etc.  to prevent possibil¡
  304.   ity of trashing directory in case of disaster.  Thanks to Jim Dennis,
  305.   jim@starshine.org, for letting me know. -Maint. ]
  306.  
  307.  
  308.   2.7.  mick@lowdown.com Finding out which directories are the largest.
  309.   Mick Ghazey,
  310.  
  311.   Ever wondered which directories are the biggest on your computer?
  312.   Here's how to find out.
  313.  
  314.  
  315.        du -S | sort -n
  316.  
  317.  
  318.  
  319.  
  320.  
  321.   2.8.  The Linux Gazette
  322.  
  323.   Kudos go to John Fisk, creator of the Linux Gazette.  This is an
  324.   excellent e-zine plus, it's FREE!!!  Now what more could you ask?
  325.   Check it out at:
  326.  
  327.  
  328.        http://www.linuxgazette.com
  329.  
  330.  
  331.   BTW, It turns out that (1) LG is now out on a monthly basis, and (2)
  332.   John Fisk no longer maintains it, the fellows at SSC do.
  333.  
  334.  
  335.  
  336.   2.9.  Ted Stern,  stern@amath.washington.edu Pointer to patch for GNU
  337.   Make 3.70 to change VPATH behavior.
  338.  
  339.   I don't know if many people have this problem, but there is a
  340.   "feature" of GNU make version 3.70 that I don't like. It is that VPATH
  341.   acts funny if you give it an absolute pathname.  There is an extremely
  342.   solid patch that fixes this, which you can get from Paul D. Smith
  343.   <psmith@wellfleet.com>.  He also posts the documentation and patch
  344.   after every revision of GNU make on the newsgroup "gnu.utils.bug"
  345.   Generally, I apply this patch and recompile gmake on every system I
  346.   have access to.
  347.  
  348.  
  349.   2.10.  How do I stop my system from fscking on each reboot? Dale Lutz,
  350.   dal@wimsey.com
  351.  
  352.   Q:  How do I stop e2fsck from checking my disk every time I boot up.
  353.  
  354.   A:  When you rebuild the kernel, the filesystem is marked as 'dirty'
  355.   and so your disk will be checked with each boot.  The fix is to run:
  356.  
  357.   rdev -R /zImage 1
  358.  
  359.   This fixes the kernel so that it is no longer convinced that the
  360.   filesystem is dirty.
  361.  
  362.   Note: If using lilo, then add read-only to your linux setup in your
  363.   lilo config file (Usually /etc/lilo.conf)
  364.  
  365.  
  366.   2.11.  How to avoid fscks caused by "device busy" at reboot time. Jon
  367.   Tombs,  jon@gtex02.us.es
  368.  
  369.   If you often get device busy errors on shutdown that leave the
  370.   filesystem in need of an fsck upon reboot, here is a simple fix:
  371.  
  372.   To /etc/rc.d/init.d/halt or /etc/rc.d/rc.0, add the line
  373.  
  374.  
  375.        mount -o remount,ro /mount.dir
  376.  
  377.  
  378.  
  379.  
  380.   for all your mounted filesystems except /, before the call to umount
  381.   -a. This means if, for some reason, shutdown fails to kill all pro¡
  382.   cesses and umount the disks they will still be clean on reboot. Saves
  383.   a lot of time at reboot for me.
  384.  
  385.  
  386.  
  387.  
  388.   2.12.  How to find the biggest files on your hard-drive.
  389.  
  390.   Simon Amor, simon@foobar.co.uk
  391.  
  392.  
  393.  
  394.        ls -l | sort +4n
  395.  
  396.  
  397.   Or, for those of you really scrunched for space this takes awhile but
  398.   works great:
  399.  
  400.  
  401.  
  402.        cd /
  403.        ls -lR | sort +4n
  404.  
  405.  
  406.  
  407.  
  408.  
  409.   2.13.  How to print pages with a margin for hole punching. Mike
  410.   Dickey,  mdickey@thorplus.lib.purdue.edu
  411.  
  412.  
  413.  
  414.        ______________________________________________________________________
  415.                #!/bin/sh
  416.                # /usr/local/bin/print
  417.                # a simple formatted printout, to enable someone to
  418.                # 3-hole punch the output and put it in a binder
  419.  
  420.                cat $1 | pr -t -o 5 -w 85 | lpr
  421.        ______________________________________________________________________
  422.  
  423.  
  424.  
  425.  
  426.  
  427.   2.14.  Raul Deluth Miller,  rockwell@nova.umd.edu A way to search
  428.   through trees of files for a particular regular expression.
  429.  
  430.   I call this script 'forall'.  Use it like this:
  431.  
  432.  
  433.        forall /usr/include grep -i ioctl
  434.        forall /usr/man grep ioctl
  435.  
  436.  
  437.  
  438.  
  439.   Here's forall:
  440.  
  441.  
  442.        ______________________________________________________________________
  443.        #!/bin/sh
  444.        if [ 1 = `expr 2 \> $#` ]
  445.        then
  446.                echo Usage: $0 dir cmd [optargs]
  447.                exit 1
  448.        fi
  449.        dir=$1
  450.        shift
  451.        find $dir -type f -print | xargs "$@"
  452.        ______________________________________________________________________
  453.  
  454.  
  455.  
  456.  
  457.  
  458.   2.15.  Barry Tolnas,  tolnas@nestor.engr.utk.edu A script for cleaning
  459.   up after programs that create autosave and backup files.
  460.  
  461.   Here is a simple two-liner which recursively descends a directory
  462.   hierarchy removing emacs auto-save (#) and backup (~) files, .o files,
  463.   and  TeX .log files. It also compresses .tex files and README files. I
  464.   call it 'squeeze' on my system.
  465.  
  466.  
  467.        ______________________________________________________________________
  468.        #!/bin/sh
  469.        #SQUEEZE removes unnecessary files and compresses .tex and README files
  470.        #By Barry tolnas, tolnas@sun1.engr.utk.edu
  471.        #
  472.        echo squeezing $PWD
  473.        find  $PWD \( -name \*~ -or -name \*.o -or -name \*.log -or -name \*\#\) -exec
  474.        rm -f {} \;
  475.        find $PWD \( -name \*.tex -or -name \*README\* -or -name \*readme\* \) -exec gzip -9 {} \;
  476.        ______________________________________________________________________
  477.  
  478.  
  479.  
  480.  
  481.  
  482.   2.16.  simon@foobar.co.uk How to find out what process is eating the
  483.   most memory. Simon Amor,
  484.  
  485.  
  486.  
  487.        ps -aux | sort +4n
  488.  
  489.  
  490.  
  491.  
  492.   -OR-
  493.  
  494.  
  495.        ps -aux | sort +5n
  496.  
  497.  
  498.  
  499.  
  500.  
  501.   2.17.  Rigging vi for C programming, Paul Anderson, Tips-HOWTO Main¡
  502.   tainer
  503.  
  504.   I do a lot of C programming in my spare time, and I've taken the time
  505.   to rig vi to be C friendly.  Here's my .exrc:
  506.  
  507.  
  508.        ______________________________________________________________________
  509.        set autoindent
  510.        set shiftwidth=4
  511.        set backspace=2
  512.        set ruler
  513.        ______________________________________________________________________
  514.  
  515.  
  516.  
  517.  
  518.   What does this do?  autoindent causes vi to automatically indent each
  519.   line following the first one indented, shiftwidth sets the distance of
  520.   ^T to 4 spaces, backspace sets the backspace mode, and ruler makes it
  521.   display the line number.  Remember, to go to a specific line number,
  522.   say 20, use:
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.   ______________________________________________________________________
  530.   vi +20 myfile.c
  531.   ______________________________________________________________________
  532.  
  533.  
  534.  
  535.  
  536.  
  537.   2.18.  Using ctags to ease programming.
  538.  
  539.   Most hackers already have ctags on their computers, but don't use it.
  540.   It can be very handy for editing specific functions.  Suppose you have
  541.   a function, in one of many source files in a directory for a program
  542.   you're writing, and you want to edit this function for updates.  We'll
  543.   call this function foo().  You don't where it is in the source file,
  544.   either.  This is where ctags comes in handy.  When run, ctags produces
  545.   a file named tags in the current dir, which is a listing of all the
  546.   functions, which files they're in and where they are in said files.
  547.   The tags file looks like this:
  548.  
  549.  
  550.  
  551.        ______________________________________________________________________
  552.  
  553.        ActiveIconManager       iconmgr.c       /^void ActiveIconManager(active)$/
  554.        AddDefaultBindings      add_window.c    /^AddDefaultBindings ()$/
  555.        AddEndResize    resize.c        /^AddEndResize(tmp_win)$/
  556.        AddFuncButton   menus.c /^Bool AddFuncButton (num, cont, mods, func, menu, item)$/
  557.        AddFuncKey      menus.c /^Bool AddFuncKey (name, cont, mods, func, menu, win_name, action)$/
  558.        AddIconManager  iconmgr.c       /^WList *AddIconManager(tmp_win)$/
  559.        AddIconRegion   icons.c /^AddIconRegion(geom, grav1, grav2, stepx, stepy)$/
  560.        AddStartResize  resize.c        /^AddStartResize(tmp_win, x, y, w, h)$/
  561.        AddToClientsList        workmgr.c       /^void AddToClientsList (workspace, client)$/
  562.        AddToList       list.c  /^AddToList(list_head, name, ptr)$/
  563.        ______________________________________________________________________
  564.  
  565.  
  566.  
  567.  
  568.  
  569.   To edit, say AddEndResize() in vim, run:
  570.  
  571.  
  572.  
  573.        vim -t AddEndResize
  574.  
  575.  
  576.  
  577.  
  578.   This will bring the appropriate file up in the editor, with the cursor
  579.   located at the beginning of the function.
  580.  
  581.  
  582.  
  583.  
  584.   2.19.  paul@geeky1.ebtech.net Why does sendmail hang for 5 minutes on
  585.   startup with RedHat? Paul Anderson,
  586.  
  587.   This is a fairly common problem, almost to the point of being a FAQ.
  588.   I don't know if RedHat has fixed this bug in their distribution, but
  589.   you can repair it yourself.  If you look in your /etc/hosts file, you
  590.   will find it looks something like:
  591.  
  592.  
  593.        127.0.0.1               localhost       yourbox
  594.  
  595.   When sendmail starts, it does a lookup on your hostname(in this
  596.   example, yourbox).  It then finds that the IP for yourbox is
  597.   127.0.0.1, sendmail doesn't like this, so it does the lookup again.
  598.   It continues with this for a while until it eventually gives up and
  599.   exits.  Fixing the problem is extremely easy, edit your /etc/hosts
  600.   file and change it to something like this:
  601.  
  602.  
  603.        127.0.0.1               localhost
  604.        10.56.142.1             yourbox
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.   2.20.  How do I configure RedHat for using color-ls? Paul Anderson,
  612.   paul@geeky1.ebtech.net
  613.  
  614.   RedHat's distribution comes with color-ls, however why they don't
  615.   configure it for colour use by default is beyond me.  Here's to fix
  616.   it.
  617.  
  618.   First, type eval `DIRCOLORS`
  619.  
  620.   Next, alias ls='ls --color=auto'
  621.  
  622.   And put the 'alias.....' in your /etc/bashrc
  623.  
  624.  
  625.  
  626.  
  627.   2.21.  vps@unicorn.niimm.spb.su How do I find which library in
  628.   /usr/lib holds a certain function? Pawel Veselow,
  629.  
  630.   What if you're compiling and you've missed a library that needed
  631.   linking in?  All gcc reports are function names...  Here's a simple
  632.   command that'll find what you're looking for:
  633.  
  634.  
  635.        for i in *; do echo $i:;nm $i|grep tgetnum 2>/dev/null;done
  636.  
  637.  
  638.  
  639.  
  640.   Where tgetnum is the name of the function you're looking for.
  641.  
  642.  
  643.  
  644.   2.22.  I compiled a small test program in C, but when I run it, I get
  645.   no output!
  646.  
  647.   You probably compiled the program into a binary named test, didn't
  648.   you?  Linux has a program called test, which tests if a certain
  649.   condition is true, it never produces any output on the screen.
  650.   Instead of just typing test, try: ./test
  651.  
  652.  
  653.  
  654.  
  655.   3.  Detailed Tips
  656.  
  657.   3.1.  Sharing swap partitions between Linux and Windows. Tony Acero,
  658.   ace3@midway.uchicago.edu
  659.  
  660.  
  661.   1. Format the partition as a dos partition, and create the Windows
  662.      swap file on it, but don't run windows yet. (You want to keep the
  663.      swap file completely empty for now, so that it compresses well).
  664.  
  665.   2. Boot linux and save the partition into a file.  For example if the
  666.      partition was /dev/hda8:
  667.  
  668.  
  669.        dd if=/dev/hda8 of=/etc/dosswap
  670.  
  671.  
  672.  
  673.  
  674.   3. Compress the dosswap file; since it is virtually all 0's it will
  675.      compress very well
  676.  
  677.  
  678.        gzip -9 /etc/dosswap
  679.  
  680.  
  681.  
  682.  
  683.   4. Add the following to the /etc/rc file to prepare and install the
  684.      swap space under Linux:
  685.  
  686.      XXXXX is the number of blocks in the swap partition
  687.  
  688.  
  689.        mkswap /dev/hda8 XXXXX
  690.        swapon -av
  691.  
  692.  
  693.  
  694.  
  695.   Make sure you add an entry for the swap partition in your /etc/fstab
  696.   file
  697.  
  698.   5. If your init/reboot package supports /etc/brc or /sbin/brc add the
  699.      following to /etc/brc, else do this by hand when you want to boot
  700.      to dos|os/2 and you want to convert the swap partition back to the
  701.      dos/windows version:
  702.  
  703.  
  704.  
  705.        swapoff -av
  706.        zcat /etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100
  707.  
  708.  
  709.  
  710.  
  711.   # Note that this only writes the first 100 blocks back to the parti¡
  712.   tion. I've found empirically that this is sufficient
  713.  
  714.   >>  What are the pros and cons of doing this?
  715.  
  716.   Pros: you save a substantial amount of disk space.
  717.  
  718.   Cons: if step 5 is not automatic, you have to remember to do it by
  719.   hand, and it slows the reboot process by a nanosecond :-)
  720.  
  721.  
  722.   3.2.  Desperate Undelete. Michael Hamilton,  michael@actrix.gen.nz
  723.  
  724.   Here's a trick I've had to use a few times.
  725.  
  726.  
  727.   Desperate person's text file undelete.
  728.  
  729.   If you accidentally remove a text file, for example, some email, or
  730.   the results of a late night programming session, all may not be lost.
  731.   If the file ever made it to disk, ie it was around for more than 30
  732.   seconds, its contents may still be in the disk partition.
  733.  
  734.   You can use the grep command to search the raw disk partition for the
  735.   contents of file.
  736.  
  737.   For example, recently, I accidentally deleted a piece of email.  So I
  738.   immediately ceased any activity that could modify that partition: in
  739.   this case I just refrained from saving any files or doing any compiles
  740.   etc.  On other occasions, I've actually gone to the trouble of bring
  741.   the system down to single user mode, and unmounted the filesystem.
  742.  
  743.   I then used the egrep command on the disk partition:  in my case the
  744.   email message was in /usr/local/home/michael/, so from the output from
  745.   df, I could see this was in /dev/hdb5
  746.  
  747.  
  748.          sputnik3:~ % df
  749.            Filesystem         1024-blocks  Used Available Capacity Mounted on
  750.            /dev/hda3              18621    9759     7901     55%   /
  751.            /dev/hdb3             308852  258443    34458     88%   /usr
  752.            /dev/hdb5             466896  407062    35720     92%   /usr/local
  753.  
  754.            sputnik3:~ % su
  755.            Password:
  756.            [michael@sputnik3 michael]# egrep -50 'ftp.+COL' /dev/hdb5 > /tmp/x
  757.  
  758.  
  759.  
  760.  
  761.  
  762.   Now I'm ultra careful when fooling around with disk partitions, so I
  763.   paused to make sure I understood the command syntax BEFORE pressing
  764.   return.  In this case the email contained the word 'ftp' followed by
  765.   some text followed by the word 'COL'.  The message was about 20 lines
  766.   long, so I used -50 to get all the lines around the phrase.  In the
  767.   past I've used -3000 to make sure I got all the lines of some source
  768.   code.  I directed the output from the egrep to a different disk parti¡
  769.   tion - this prevented it from over writing the message I was looking
  770.   for.
  771.  
  772.   I then used strings to help me inspect the output
  773.  
  774.  
  775.           strings /tmp/x | less
  776.  
  777.  
  778.  
  779.  
  780.  
  781.   Sure enough the email was in there.
  782.  
  783.   This method can't be relied on, all, or some, of the disk space may
  784.   have already been re-used.
  785.  
  786.   This trick is probably only useful on single user systems.  On multi-
  787.   users systems with high disk activity, the space you free'ed up may
  788.   have already been reused.  And most of use can't just rip the box out
  789.   from under our users when ever we need to recover a file.
  790.  
  791.   On my home system this trick has come in handy on about three
  792.   occasions in the past few years - usually when I accidentally trash
  793.   some of the days work.  If what I'm working survives to a point where
  794.   I feel I made significant progress, it get's backed up onto floppy, so
  795.   I haven't needed this trick very often.
  796.  
  797.  
  798.  
  799.   3.3.  How to use the immutable flag. Jim Dennis,  jadestar@rahul.net
  800.  
  801.   Use the Immutable Flag
  802.  
  803.   Right after you install and configure your system go through the /bin,
  804.   /sbin/, /usr/bin, /usr/sbin and /usr/lib (and a few of the other usual
  805.   suspects and make liberal use of the 'chattr +i command'.  Also add
  806.   that to the the kernel files in root.  Now 'mkdir /etc/.dist/' copy
  807.   everything from /etc/ on down (I do this in two steps using
  808.   /tmp/etcdist.tar to avoid recursion) into that directory.  (Optionally
  809.   you can just create /etc/.dist.tar.gz) -- and mark that as immutable.
  810.  
  811.   The reason for all of this is to limit the damage that you can do when
  812.   logged in as root.  You won't overwrite files with a stray redirection
  813.   operator, and you won't make the system unusable with a stray space in
  814.   an 'rm -fr' command (you might still do alot of damage to your data --
  815.   but your libs and bins will be safer.
  816.  
  817.   This also makes a variety of security and denial of service exploits
  818.   either impossible or more difficult (since many of them rely on
  819.   overwriting a file through the actions of some SUID program that
  820.   *isn't providing an arbitrary shell command*).
  821.  
  822.   The only inconvenience of this is when building and doing your 'make
  823.   install' on various sorts of system binaries.  On the other hand it
  824.   also prevents the 'make install' from over-writing the files.  When
  825.   you forget to read the Makefile and chattr -i the files that are to be
  826.   overwritten (and the directories to which you want to add files) --
  827.   the make fails, you just use the chattr command and rerun it.  You can
  828.   also take that opportunity to move your old bin's, libs, or whatever
  829.   into a .old/ directory or rename or tar them or whatever.
  830.  
  831.  
  832.   3.4.  Jim Dennis,  jadestar@rahul.net A suggestion for where to put
  833.   new stuff.
  834.  
  835.   All new stuff starts under /usr/local! or /usr/local/`hostname`
  836.  
  837.   If your distribution is one that leaves /usr/local empty then just
  838.   create your /usr/local/src, /usr/local/bin etc and use that.  If your
  839.   distribution puts things in the /usr/local tree than you may want to
  840.   'mkdir /usr/local/`hostname`' and give the 'wheel' group +w to it (I
  841.   also make it SUID and SGID to insure that each member of the wheel
  842.   group can only mess with their own files thereunder, and that all
  843.   files created will belong to the 'wheel' group.
  844.  
  845.   Now discipline yourself to *ALWAYS! ALWAYS! ALWAYS!* put new packages
  846.   under /usr/local/src/.from/$WHEREVER_I_GOT_IT/ (for the .tar or
  847.   whatever files) and build them  under /usr/local/src (or
  848.   .../$HOSTNAME/src).  Make sure that it installs under the local
  849.   hierarchy.  If it *absolutely must* be installed back in /bin or
  850.   /usr/bin or somewhere else -- put a symlink from the local heirarchy
  851.   to each element that when anywhere else.
  852.  
  853.   The reason for this -- even though it's more work -- is that it helps
  854.   isolate what has to be backed up and restored or reinstalled in the
  855.   event of a full re-install from the distribution medio (usually CD
  856.   these days).  By using a /usr/local/.from directory you also keep an
  857.   informal log of where your sources are coming from -- which helps when
  858.   you're looking for new updates -- and may be critical when monitoring
  859.   the security announcement lists.
  860.  
  861.   One of my systems at home (the one I'm calling from) was put together
  862.   before I adopted these policies for myself.  I still don't "know" all
  863.   the ways that it differs from the stock "as installed" system.  This
  864.   is despite the fact that I've done very little with my home system's
  865.   configuration and I'm the *only* person who ever uses it.
  866.  
  867.   By contrast the systems I've set up at work (when I was thrust into
  868.   the role of system administrator there) have all been configured this
  869.   way -- have been administered by many contractors and other MIS
  870.   people, and have had a large number of upgrades and package
  871.   installations.  Nonetheless I have a very good idea which precise
  872.   elements were put in *after* the initial installation and
  873.   configuration.
  874.  
  875.  
  876.   3.5.  Converting all files in a directory to lowercase. Justin Dossey,
  877.   dossey@ou.edu
  878.  
  879.  
  880.   I noticed a few overly difficult or unnecessary procedures recommended
  881.   in the 2c tips section of Issue 12.  Since there is more than one, I'm
  882.   sending it to you:
  883.  
  884.  
  885.        ______________________________________________________________________
  886.        #!/bin/sh
  887.                 # lowerit
  888.                 # convert all file names in the current directory to lower case
  889.                 # only operates on plain files--does not change the name of directories
  890.                 # will ask for verification before overwriting an existing file
  891.                 for x in `ls`
  892.                   do
  893.                   if [ ! -f $x ]; then
  894.                     continue
  895.                     fi
  896.                   lc=`echo $x  | tr '[A-Z]' '[a-z]'`
  897.                   if [ $lc != $x ]; then
  898.                     mv -i $x $lc
  899.                   fi
  900.                   done
  901.        ______________________________________________________________________
  902.  
  903.  
  904.  
  905.  
  906.   Wow.  That's a long script.  I wouldn't write a script to do that;
  907.   instead, I would use this command:
  908.  
  909.  
  910.        for i in * ; do [ -f $i ] && mv -i $i `echo $i | tr '[A-Z]' '[a-z]'`;
  911.        done;
  912.  
  913.  
  914.  
  915.  
  916.   on the command line.
  917.  
  918.   The contributor says he wrote the script how he did for
  919.   understandability (see below).
  920.  
  921.   On the next tip, this one about adding and removing users, Geoff is
  922.   doing fine until that last step.  Reboot?  Boy, I hope he doesn't
  923.   reboot every time he removes a user.  All you have to do is the first
  924.   two steps.  What sort of processes would that user have going, anyway?
  925.   An irc bot?  Killing the processes with a simple
  926.  
  927.  
  928.        kill -9 `ps -aux |grep ^<username> |tr -s " " |cut -d " " -f2`
  929.  
  930.  
  931.  
  932.  
  933.   Example, username is foo
  934.  
  935.  
  936.        kill -9 `ps -aux |grep ^foo |tr -s " " |cut -d " " -f2`
  937.  
  938.  
  939.  
  940.  
  941.   That taken care of, let us move to the forgotten root password.
  942.  
  943.   The solution given in the Gazette is the most universal one, but not
  944.   the easiest one.  With both LILO and loadlin, one may provide the boot
  945.   parameter "single" to boot directly into the default shell with no
  946.   login or password prompt.  From there, one may change or remove any
  947.   passwords before typing "init 3" to start multiuser mode.  Number of
  948.   reboots: 1 The other way Number of reboots: 2
  949.  
  950.  
  951.   Justin Dossey
  952.  
  953.  
  954.  
  955.   3.6.  Paul Anderson,  paul@geeky1.ebtech.net How To Upgrade Sendmail
  956.  
  957.   We're starting from raw, clean source.  First, obtain the sendmail
  958.   source code.  I've d/led version 8.9.0, which is, as you will notice,
  959.   bleeding edge.  I grabbed it from
  960.   ftp.sendmail.org:/pub/sendmail/sendmail.8.9.0.tar.gz
  961.  
  962.   It's about 1Meg, and considering I'm running 8.7.6, I think it's worth
  963.   the effort.  If this works, you'll undoubtedly hear about it, elsewise
  964.   I can't get the new HOWTO versions out without e-mail:)
  965.  
  966.   Now, once you've got the source d/led, unpack it.  It'll create a dir
  967.   called sendmail-8.9.0 in the current directory.  Change into that
  968.   directory, read the README and RELEASE_NOTES files(and be amazed at
  969.   the updates they've done).  Now, cd in src.  This is where most of
  970.   your work will be done.
  971.  
  972.   A quick note: Sendmail is a small, powerful and well-written program.
  973.   The sendmail binary itself compiled in less than 5 minutes on my 5x86
  974.   133 with 32Megs RAM!  The entire compile and install(sans config) took
  975.   under 15 minutes!
  976.  
  977.   I don't normally run BIND on my system, so I found the lines:
  978.  
  979.  
  980.  
  981.        ______________________________________________________________________
  982.        # ifndef NAMED_BIND
  983.        #  define NAMED_BIND    1       /* use Berkeley Internet Domain Server */
  984.        # endif
  985.        ______________________________________________________________________
  986.  
  987.  
  988.  
  989.  
  990.  
  991.   and changed the 1 to a 0, ala:
  992.  
  993.  
  994.  
  995.        ______________________________________________________________________
  996.        # ifndef NAMED_BIND
  997.        #  define NAMED_BIND    0       /* use Berkeley Internet Domain Server */
  998.        # endif
  999.        ______________________________________________________________________
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.   On Debian 1.3.1, db.h is by default installed in /usr/include/db,
  1006.   instead of /usr/include, where sendmail hopes to find it.  Change to
  1007.   the src, mailstats, makemap, praliases, rmail and smrsh directories
  1008.   and execute the following command:
  1009.  
  1010.  
  1011.  
  1012.         ./Build -I/usr/include/db
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.   Once you've done that, cd .. and type make install.  There!  Sendmail
  1019.   version 8.9.0 should now be installed!  This is, of course, assuming
  1020.   you already have your original configuration.  For everything to work
  1021.   smoothly on my system, since I host free mailing lists for people
  1022.   using majordomo, I had to add the following to the beginning of my
  1023.   /etc/sendmail.cf:
  1024.  
  1025.  
  1026.  
  1027.        ______________________________________________________________________
  1028.        O DontBlameSendmail=forwardfileinunsafedirpath, forwardfileinunsafedirpathsafe
  1029.        ______________________________________________________________________
  1030.  
  1031.  
  1032.  
  1033.  
  1034.   Sendmail 8.9.0 is rather pedantic about directory and file permissions
  1035.   these days, and will complain about dirs and files in aliases or
  1036.   .forward files that are group or world writeable.  While it's not a
  1037.   good idea to disable this pedantry, I am only running with a single
  1038.   person at the console and I felt it was okay to allow this minor
  1039.   security hole.  YMMV.
  1040.  
  1041.  
  1042.  
  1043.  
  1044.   3.7.  Jim Dennis,  jadestar@rahul.net Some tips for new sysadmins.
  1045.  
  1046.   Create and maintain a /README.`hostname` and/or a
  1047.   /etc/README.`hostname` [Or possibly /usr/local/etc/README.`hostname`
  1048.   -Maint. ]
  1049.  
  1050.   Absolutely, from *day one* of administering a system take notes in an
  1051.   online log file.  You might make "vi /README.$(hostname)" a line in
  1052.   root's  /bash_logout.  Another way to do this is to write an su or a
  1053.   sudo script that does something like:
  1054.  
  1055.  
  1056.  
  1057.                   function exit \
  1058.                           { unset exit; exit; \
  1059.                             cat ~/tmp/session.$(date +%y%m%d) \
  1060.                             >> /README.$(hostname) && \
  1061.                             vi /README.$(hostname)
  1062.                             }
  1063.                   script -a ~/tmp/session.$(date +%y%m%d)
  1064.                   /bin/su.org -
  1065.  
  1066.  
  1067.  
  1068.  
  1069.   (use the typescript command to create a session log and create a
  1070.   function to automate appending and updating the log).
  1071.  
  1072.   I'll admit that I haven't implemented this automation of policy --
  1073.   I've just relied on self-discipline so far.  However I have been
  1074.   toying with the idea (even to the point of prototyping the scripts and
  1075.   shell functions as you see them).  One thing that holds me back on
  1076.   this is the 'script' command itself.  I think I'll have to grab the
  1077.   sources and add a couple of command line parameters (to pause/stop the
  1078.   script recording from the command line) before I commit to using
  1079.   this).
  1080.  
  1081.   My last suggestion (for this round):
  1082.  
  1083.   Root's path should consist of 'PATH= /bin'
  1084.  
  1085.   That's it.  Nothing else on root's path.  Everything root does is
  1086.   provided by a symlink from  /bin or by an alias or shell function, or
  1087.   is a script or binary in  /bin, or is typed out with an explicit path.
  1088.  
  1089.   This makes anyone running as root aware (sometimes painfully so) of
  1090.   how he or she is trusting binaries.  The wise admin of a multi-user
  1091.   host will periodically look through his or here  /bin and  /.*history
  1092.   files to look for patterns and loopholes.
  1093.  
  1094.   The really motivated admin will spot sequences that can be automated,
  1095.   places where sanity checks can be inserted, and tasks for which "root"
  1096.   privileges should be temporarily eschewed (launching editors, MTA's
  1097.   and other large interactive programs with elaborate scripting features
  1098.   that *might* be embedded in transparent or data files -- like the
  1099.   infamous vi ./.exrc and emacs ./.emacs and the even more insidous
  1100.   $EXINIT and the embedded header/footer macros).  Naturally those sorts
  1101.   of commands can be run with something like:
  1102.  
  1103.  
  1104.                        cp $data $some_users_home/tmp
  1105.                        su -c $origcommand $whatever_switches
  1106.                        cp $some_users_home/tmp $data
  1107.  
  1108.  
  1109.  
  1110.  
  1111.   (...where the specifics depend on the command).
  1112.  
  1113.   Mostly these last sorts of precautions are overboard for the home or
  1114.   "single" user workstation -- but they are very good policy the admin
  1115.   of a multi-user -- particular a publicly exposed system (like the
  1116.   one's at netcom).
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.   3.8.  How to configure xdm's chooser for host selection. Arrigo Tri¡
  1124.   ulzi,  a.triulzi@ic.ac.uk
  1125.  
  1126.  
  1127.   1. Edit the file that launches xdm most likely /etc/rc/rc.6 or
  1128.      /etc/rc.local) so that it contains the following lines in the xdm
  1129.      startup section.
  1130.  
  1131.  
  1132.  
  1133.        /usr/bin/X11/xdm
  1134.        exec /usr/bin/X11/X -indirect hostname
  1135.  
  1136.  
  1137.  
  1138.  
  1139.   2. Edit /usr/lib/X11/xdm/Xservers and comment out the line which
  1140.      starts the server on the local machine (i.e. starting 0:)
  1141.  
  1142.   3. Reboot the machine and you're home and away.
  1143.  
  1144.   I add this because when I was, desperately, trying to set it up for my
  1145.   own subnet over here it took me about a week to suss out all the
  1146.   problems.
  1147.  
  1148.   Caveat: with old SLS (1.1.1) for some reason you can leave a -nodaemon
  1149.   after the xdm line -- this does NOT work for later releases.
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.