   Linux Tips HOWTO
  Paul Anderson, paul@geeky1.ebtech.net
  v3.1, 26  1997

    HOWTO    ,  
        Linux .
  ______________________________________________________________________

  Table of Contents


  1. 

  2.  

     2.1  Syslog 
     2.2 Script      HOWTOs.
     2.3    ;;;
     2.4       log  .
     2.5  Script     Core .
     2.6     s.
     2.7      .
     2.8  Linux Gazette
     2.9   patch   GNU Make 3.70       VPATH.
     2.10        fsck   ;
     2.11     fscks    "device busy"    .
     2.12         .
     2.13           .
     2.14              .
     2.15  script      autosave  backup    .
     2.16         .
     2.17   vi    C ,
     2.18   sendmail   5      RedHat;
     2.19    RedHat     color-ls;
     2.20      /usr/lib    ;

  3.  

     3.1   swap partitions  Linux  Windows.
     3.2  Undelete.
     3.3      flag.
     3.4         .
     3.5           .
     3.6     sysadmins.
     3.7     xdm's chooser   host.
     3.8    


  ______________________________________________________________________

  [1m1.  [0m

     [1mLinux Tips HOWTO[22m,      
       Linux  .    
      '  ,    
   Tips-HOWTO (, ,      ,
  ;).   , ,      
            
  Tips-HOWTO.

  Paul Anderson [4m--Linux[24m [4mTIPS[24m [4mHOWTO[0m

  panderso@ebtech.net



  [1m2.   [0m

  [1m2.1.   Syslog  Paul Anderson,   Tips-HOWTO[0m

     /etc/syslog.conf,     :


       # Dump everything on tty8
       *.*                                     /dev/tty8




  : [4m[24m [4m[24m [4m[24m [4m[24m [4mTABS![24m  syslog 
    ...


  [1m2.2.  Script      HOWTOs. Didier Juges,[0m
  [1mdj@destin.nfds.net[0m


  '     ,     script 
         howto.   howto 
     /usr/doc/faq/howto/   . 
      XXX-HOWTO.gz,  XXX    
  howto.    script   "howto"   the
  /usr/local/sbin :


       ______________________________________________________________________
       #!/bin/sh
       if [ "$1" = "" ]; then
           ls /usr/doc/faq/howto | less
       else
           gunzip -c /usr/doc/faq/howto/$1-HOWTO.gz | less
       fi
       ______________________________________________________________________




     ,     
   howto.         
    (  ),   (  
   )     .

   ,      Serial-HOWTO.gz , :

  $ howto Serial



  [1m2.3.     ;;; Hans Zoebelein,  zocki@gold-[0m
  [1mfish.cube.net[0m

     script      
          mount
  (, cdrom, ...)

     ,     X  
     1   mail    .





  ______________________________________________________________________
  #!/bin/sh

  #
  # $Id: check_hdspace,v 1.18 1996/12/11 22:33:29 root Exp root $
  #

  #
  # Since I got mysterious error messages during compile when
  # tmp files filled up my disks, I wrote this to get a warning
  # before disks are full.
  #
  # If this stuff saved your servers from exploding,
  # send praising email to zocki@goldfish.cube.net.
  # If your site burns down because of this, sorry but I
  # warned you: no comps.
  # If you really know how to handle sed, please forgive me :)
  #

  #
  # Shoot and forget: Put 'check_hdspace &' in rc.local.
  # Checks for free space on devices every $SLEEPTIME sec.
  # You even might check your floppies or tape drives. :)
  # If free space is below $MINFREE (kb), it will echo a warning
  # and send one mail for each triggering device to $MAIL_TO_ME.
  # If there is more free space than trigger limit again,
  # mail action is also armed again.
  #

  # TODO: Different $MINFREE for each device.
  # Free /*tmp dirs securely from old junk stuff if no more free space.


  DEVICES='/dev/sda2 /dev/sda8 /dev/sda9'         # device; your put disks here
  MINFREE=20480                                   # kb; below this do warning
  SLEEPTIME=10                                    # sec; sleep between checks
  MAIL_TO_ME='root@localhost'                     # fool; to whom mail warning


  # ------- no changes needed below this line (hopefully :) -------

  MINMB=0
  ISFREE=0
  MAILED=""
  let MINMB=$MINFREE/1024         # yep, we are strict :)

  while [ 1 ]; do
          DF="`/bin/df`"
                  for DEVICE in $DEVICES ; do
                  ISFREE=`echo $DF | sed s#.\*$DEVICE" "\*[0-9]\*""\*[0-9]\*" "\*## | sed s#" ".\*##`

                  if [ $ISFREE -le $MINFREE ] ; then
                          let ISMB=$ISFREE/1024
                          echo  "WARNING: $DEVICE only $ISMB mb free." >&2
                          #echo "more stuff here" >&2
                          echo -e "\a\a\a\a"

                          if [ -z  "`echo $MAILED | grep -w $DEVICE`" ] ; then
                                  echo "WARNING: $DEVICE only $ISMB mb free.      (Trigger is set to $MINMB mb)" \
                                  | mail -s "WARNING: $DEVICE only $ISMB mb free!" $MAIL_TO_ME
                                  MAILEDH="$MAILED $DEVICE"
                                  MAILED=$MAILEDH
                                  # put further action here like cleaning
                                  # up */tmp dirs...
                          fi
                          elif [ -n  "`echo $MAILED | grep -w $DEVICE`" ] ; then
                                  # Remove mailed marker if enough disk space
                                  # again. So we are ready for new mailing action.
                                  MAILEDH="`echo $MAILED  | sed s#$DEVICE##`"
                                  MAILED=$MAILEDH
                          fi

                  done
                  sleep $SLEEPTIME

  done
  ______________________________________________________________________






  [1m2.4.        log  . Paul[0m
  [1mAnderson,   Tips-HOWTO >[0m

      ,     250 ,  100+
       UUCP.  ,    
        logs;    chklogs.   Chklogs
     Emilio Grimaldo, grimaldo@panama.iaehv.nl,  
    1.8   
  ftp.iaehv.nl:/pub/users/grimaldo/chklogs-1.8.tar.gz.   
     ( , ,   
   sub).    ,   
  crontab   :


       # Run chklogs at 9:00PM daily.
       00 21 * * *       /usr/local/sbin/chklogs -m




     ,      
       :)



  [1m2.5.  ohammers@cu-online.com  Script     Core[0m
  [1m. Otto Hammersmith,[0m

       rmcores (   
  handle-cores)      :



















  ______________________________________________________________________
  #!/bin/sh
  USAGE="$0 <directory> <message-file>"

  if [ $# != 2 ] ; then
          echo $USAGE
          exit
  fi

   echo Deleting...
  find $1 -name core -atime 7 -print -exec rm {} \;

  echo e-mailing
  for name in `find $1 -name core -exec ls -l {} \; | cut -c16-24`
  do
          echo $name
          cat $2 | mail $name
  done
  ______________________________________________________________________




     cron    .



  [1m2.6.      s. Alan Cox,[0m
  [1mA.Cox@swansea.ac.uk[0m

           
     


       (cd /source/directory && tar cf - . ) | (cd /dest/directory && tar xvfp -)




  [4m[[24m [4mA[24m [4m[24m [4m[24m [4m/source/directory.[24m [4m[24m [4mtar.....[24m  [4m[24m [4m[0m
  [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4mdirectory[24m [4m[24m [4m[0m
  [4m.[24m  [4m[24m [4m[24m [4mJim[24m [4mDennis,[24m [4mjadestar@rahul.net,[24m [4m[24m [4m[24m [4m[0m
  [4m.[24m [4m-.[24m [4m][0m


  [1m2.7.  mghazey@miso.lowdown.com     [0m
  [1m. Mick Ghazey,[0m

          
   ;     .


       du -S | sort -n





  [1m2.8.   Linux Gazette[0m

      John Fisk,    Linux Gazette.  
       ,  [1m!!!  [22m
     ;   :



  http://www.ssc.com/lg




    ,   (1)  LG    ,
   (2)      John Fisk ,     SSC.



  [1m2.9.  Ted Stern,  stern@amath.washington.edu   patch  [0m
  [1mGNU Make 3.70       VPATH.[0m

          ,   
  ""  GNU make  3.70     .
     VPATH       
  .     patch   
  ,        Paul D. Smith
  <psmith@wellfleet.com>.        patch
       GNU make  newsgroup gnu.utils.bug.
  ,    patch    compile  gmake  
     .


  [1m2.10.         fsck   ;[0m
  [1mDale Lutz,  dal@wimsey.com[0m

  Q:     e2fsck         
  boot.

  A:     ,     
  ''          .   
      :

  rdev -R /zImage 1

             
   .

  [4m:[24m [4m[24m [4m[24m [4mlilo,[24m [4m[24m [4m[24m [4m[24m read-only [4m[0m
  [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4mlilo[24m [4m([24m [4m[0m
  [4m/etc/lilo.conf)[0m


  [1m2.11.      fscks    "device busy"[0m
  [1m   . Jon Tombs,  jon@gtex02.us.es[0m

      device busy   shutdown   
      fsck   ,  
    :

       /etc/rc.d/init.d/halt 
  /etc/rc.d/rc.0


       mount -o remount,ro /mount.dir




      (mounted)     /, 
    umount -a.    ,   ,  shut-
  down         
        .   
    .

  [1m2.12.          .[0m

  [4mSimon[24m [4mAmor,[24m simon@foobar.co.uk



       ls -l | sort +4n




  , '     scrunched  ,   
      :



       cd /
       ls -lR | sort +4n





  [1m2.13.           [0m
  [1m. Mike Dickey,  mdickey@thorplus.lib.purdue.edu[0m



       ______________________________________________________________________
               #!/bin/sh
               # /usr/local/bin/print
               # a simple formatted printout, to enable someone to
               # 3-hole punch the output and put it in a binder

               cat $1 | pr -t -o 5 -w 85 | lpr
       ______________________________________________________________________





  [1m2.14.  Raul Deluth Miller,  rockwell@nova.umd.edu    [0m
  [1m         .[0m

     script 'forall'.      :


       forall /usr/include grep -i ioctl
       forall /usr/man grep ioctl




    script forall:












  ______________________________________________________________________
  #!/bin/sh
  if [ 1 = `expr 2 \> $#` ]
  then
          echo Usage: $0 dir cmd [optargs]
          exit 1
  fi
  dir=$1
  shift
  find $dir -type f -print | xargs "$@"
  ______________________________________________________________________





  [1m2.15.  Barry Tolnas,  tolnas@nestor.engr.utk.edu  script  [0m
  [1m   autosave  backup   [0m
  [1m.[0m

     -     
       emacs auto-save (#)  backup
  (~),   .o ,   TeX .log.     .tex
    README.    'squeeze'   .


       ______________________________________________________________________
       #!/bin/sh
       #SQUEEZE removes unnecessary files and compresses .tex and README files
       #By Barry tolnas, tolnas@sun1.engr.utk.edu
       #
       echo squeezing $PWD
       find  $PWD \( -name \*~ -or -name \*.o -or -name \*.log -or -name \*\#\) -exec
       rm -f {} \;
       find $PWD \( -name \*.tex -or -name \*README\* -or -name \*readme\* \) -exec gzip -9 {} \;
       ______________________________________________________________________





  [1m2.16.  simon@foobar.co.uk       [0m
  [1m . Simon Amor,[0m



       ps -aux | sort +4n




  -H-


       ps -aux | sort +5n





  [1m2.17.    vi    C , Paul Anderson, Tips-[0m
  [1mHOWTO [0m

      C    ,   
      vi       C.   
   .exrc:
       ______________________________________________________________________
       set autoindent
       set shiftwidth=4
       set backspace=2
       set ruler
       ______________________________________________________________________




    ;  autoindent   vi   indent 
          indent,  shiftwidth
      ^T (tab)  4 ,  backspace  
  backspace mode,   ruler    .   ,
          ,    20,
   :



       ______________________________________________________________________
       vi +20 myfile.c
       ______________________________________________________________________





  [1m2.18.  paul@geeky1.ebtech.net   sendmail   5 [0m
  [1m    RedHat; Paul Anderson,[0m

       ,     FAQ.  
     RedHat    bug   ,  
       .      /etc/hosts ,
        :


       127.0.0.1               localhost       yourbox




     sendmail,   hostname   (  
  ,  yourbox).      IP  yourbox 
  127.0.0.1,     sendmail,   .  
           .  
        ,   
  /etc/hosts       :


       127.0.0.1               localhost
       10.56.142.1             yourbox






  [1m2.19.     RedHat     color-ls; Paul[0m
  [1mAnderson,  paul@geeky1.ebtech.net[0m

    RedHat   color-ls,      
      .     .

  ,  eval `DIRCOLORS`


  , alias ls='ls --color=yes'

     'alias.....'   /etc/bashrc




  [1m2.20.  vps@unicorn.niimm.spb.su     [0m
  [1m/usr/lib    ; Pawel Veselow,[0m

      compile    link   
  ;   gcc reports   ...   
         :


       for i in *; do echo $i:;nm $i|grep tgetnum 2>/dev/null;done




   tgetnum       .




  [1m3.   [0m

  [1m3.1.    swap partitions  Linux  Windows. Tony[0m
  [1mAcero,  ace3@midway.uchicago.edu[0m


  1.   partition  dos partition,   
      swap  Windows  ,      windows.
     (     swap     , 
       ).

  2.  linux    partition   .  
        partition   /dev/hda8:


       dd if=/dev/hda8 of=/etc/dosswap




  3.    swap  dos.      0 
       


       gzip -9 /etc/dosswap




  4.      /etc/rc    
        swap    Linux:

     [4mXXXXX[24m [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4m[24m [4mswap[24m [4mpartition[0m


       mkswap /dev/hda8 XXXXX
       swapon -av




         swap partition 
   /etc/fstab

  5.     init/reboot  /etc/brc  /sbin/brc
         /etc/brc,       
         dos|os/2      swap
     partition     dos/windows:



       swapoff -av
       zcat /etc/dosswap.gz | dd of=/dev/hda8 bs=1k count=100




  # Note that this only writes the first 100 blocks back to the parti-
  tion. I've found empirically that this is sufficient

  >>           ;

  :       .

  :    5   ,    
      ,       
  nanosecond :-)


  [1m3.2.   Undelete. Michael Hamilton,  michael@actrix.gen.nz[0m

          .

  undelete    .

       text ,  ,  email, 
         , 
     .        ,   .
     30 ,     
       .

       grep     raw disk
  partition     .

   , ,       email.
  ,        
   partition:         
      (compile) .    , 
          single user mode, 
    (unmount)   .

      egrep  partition  :  
     email    /usr/local/home/michael/, 
    output  df,     /dev/hdb5


         sputnik3:~ % df
           Filesystem         1024-blocks  Used Available Capacity Mounted on
           /dev/hda3              18621    9759     7901     55%   /
           /dev/hdb3             308852  258443    34458     88%   /usr
           /dev/hdb5             466896  407062    35720     92%   /usr/local

           sputnik3:~ % su
           Password:
           [michael@sputnik3 michael]# egrep -50 'ftp.+COL' /dev/hdb5 > /tmp/x


           
  ,         
        return.      
  email    'ftp'    text  
    'COL'.      20 , 
    -50          .
       -3000      
         .    
   egrep    partition -    
        .

      strings      
   


          strings /tmp/x | less





  To email   .

           , ,  , 
         .

             
  .        ,
          . 
  ,           
         .

      ,        
      -     
   .   ,        
     ,      floppy,
          .



  [1m3.3.       flag. Jim Dennis,[0m
  [1mjadestar@rahul.net[0m

     Flag

           
  /bin, /sbin/, /usr/bin, /usr/sbin  /usr/lib (  of the
  other usual suspects      'chattr +i
  '.         root.  
  'mkdir /etc/.dist/'      /etc/ on down ( 
        /tmp/etcdist.tar   
   )    . (  
    /etc/.dist.tar.gz) --      .

              
      root.         
    (redirection operator) stray,    
       stray     'rm -fr' (
          --   
        .

          
   (denial of service)      
   (         
        SUID  * 
     *).
              'make
  install'       .    ,
     'make install'      .  
      Makefile    chattr -i  
        (    
     ) --  make , 
     chattr   .    
           bin's, lib's, 
      .old/         
  tar   .




  [1m3.4.  Jim Dennis,  jadestar@rahul.net      [0m
  [1m  .[0m

          /usr/local! 
  /usr/local/`hostname`

        /usr/local    
  /usr/local/src, /usr/local/bin .    .  
        /usr/local   
     'mkdir /usr/local/`hostname`'    
  'wheel' group +w   (   SUID  SGID  
       wheel group     
        ,      
      'wheel' group.

        *! ! !*   
      /usr/local/src/.from/$__/ (  .tar 
   )       /usr/local/src (
  .../$HOSTNAME/src).       
   .   * *    
  /bin  /usr/bin    --   symlink   
            .

    '  --       -- 
      ,      
  restore       
    distribution media ( CD   ).
    /usr/local/.from directory   
     (log)      
  --         --  
        monitore  
     .

  -       (      
      )      
      .    ""    
      " ".     
             
     **    .

  ,        (  
      )      
   --        
   MIS,        
  .           
     **     .


  [1m3.5.           [0m
  [1m. Justin Dossey,  dossey@ou.edu[0m


         
      2c tips   12.    
    ,    :


       ______________________________________________________________________
       #!/bin/sh
                # lowerit
                # convert all file names in the current directory to lower case
                # only operates on plain files--does not change the name of directories
                # will ask for verification before overwriting an existing file
                for x in `ls`
                  do
                  if [ ! -f $x ]; then
                    continue
                    fi
                  lc=`echo $x  | tr '[A-Z]' '[a-z]'`
                  if [ $lc != $x ]; then
                    mv -i $x $lc
                  fi
                  done
       ______________________________________________________________________




  ,    script.      script   
  .  ,     :


       for i in * ; do [ -f $i ] && mv -i $i `echo $i | tr '[A-Z]' '[a-z]'`;
       done;




    .

        ,     script 
         ( ).

    ,       
  ,  Geoff        .
  ;  ,       
       .  ,    
     .         ,
  ;   irc bot;       


       kill -9 `ps -aux |grep ^<username> |tr -s " " |cut -d " " -f2`




  ,  username  foo


       kill -9 `ps -aux |grep ^foo |tr -s " " |cut -d " " -f2`




      ,      
  root.


       Gazette    ,     
  .    LILO   loadlin,     
   boot     (single)    
   shell  login  password prompt.   ,
        passwords    "init
  3"       (multiuser mode).
   : 1      : 2


  Justin Dossey



  [1m3.6.  Jim Dennis,  jadestar@rahul.net    [0m
  [1msysadmins.[0m

      /README.`hostname` / 
  /etc/README.`hostname` [4m[[24m [4m[24m [4m/usr/local/etc/README.`hostname`[0m
  [4m-Maint.[24m [4m][0m

  ,    *  *  
      online log .      vi
  /README.$(hostname).      root  /bash_logout.
            su   sudo
  script      :


                       function exit \
                               { unset exit; exit; \
                                 cat ~/tmp/session.$(date +%y%m%d) \
                                 >> /README.$(hostname) && \
                                 vi /README.$(hostname)
                                 }
                       script -a ~/tmp/session.$(date +%y%m%d)
                       /bin/su.org -




  (   typescript     session
  log          
    log).

          
   --         .
  ,       (     
    (prototype)  scripts   shell  
   ).           'script'
  .             
      (  /  script 
      )      
  ).

      ('   ):

   path  Root      'PATH= /bin'

       path  root.  ,   root 
    symlink    /bin    alias  shell ,  
   script      /bin,      path.

         root   ( 
  )    .    admin  host
            /bin  
    /.*history  patterns  .

     admin    
    ,     / 
   ,      "root"   
      (   ,
  MTA's     (interactive)   
   scripting   **    
      --    vi ./.exrc   emacs
  ./.emacs      $EXINIT   
    (header/footer macros)).   
           :


                       cp $data $some_users_home/tmp
                       su -c $origcommand $whatever_switches
                       cp $some_users_home/tmp $data




  (...      ).

            
  "single"     --     
         --   
     (   netcom).



  [1m3.7.      xdm's chooser   host. Arrigo Tri-[0m
  [1mulzi,  a.triulzi@ic.ac.uk[0m


  1.       xdm   
     /etc/rc/rc.6  /etc/rc.local)      
          xdm.



       /usr/bin/X11/xdm
       exec /usr/bin/X11/X -indirect hostname




  2.   /usr/lib/X11/xdm/Xservers      
        server    (..   0:)

  3.     you're home and away.


            
    subnet        
    .

  :    SLS (1.1.1)     
    -nodaemon    xdm --  [1m [22m 
   .


  [1m3.8.     [0m

   , , ,    
     HOWTO,  email    :
  voulariba@hellug.gr     : evris@hellug.gr 
   : ep@rocketmail.com



































































