Miscellaneous Cleanup

Applicable to: FreeBSD 3.x, 4.x
Updated: January 1, 2001

This Sheet describes some additional housekeeping items that will make life under Unix a little more pleasant.

  1. Edit /etc/crontab to eliminate annoying e-mails:

    MAILTO=""

  2. Create script files to easily mount and unmount the CDROM drive:

    1. Create /usr/local/bin/cdin:

      #!/bin/sh
      mount_cd9660 /dev/acd0c /cdrom

    2. Create /usr/local/bin/cdout:

      #!/bin/sh
      umount /cdrom
      cdcontrol -f /dev/acd0c eject

      Make the scripts executable by root only:

      # chown root:wheel /usr/local/bin/cd*
      # chmod u+x /usr/local/bin/cd*

  3. Create a nightly status report for some items that aren't part of the standard periodic reports.

    1. Create a mailable report script, /usr/local/bin/nitestat:
      #! /bin/sh
      #
      # nitestat - Nightly Log Report
      #
      # Maintained by:        D. O'Connor
      # Modified:             7/22/2000.
      #
      
      MSG="/var/log/messages"
      SEC="/var/log/security"
      HTP="/var/log/httpd-error.log"
      OLD="0"
      ZIP="gz"
      ZIPPROG="/usr/bin/gzip"
      UNZIPPROG="/usr/bin/gunzip"
      
      MM=`date | awk '{print $2}'`
      DD=`date | awk '{printf "%3s", $3}'`
      MSG_LFTO=`cat ${MSG} | grep -e "${MM}${DD}" | grep -e "logfile turned over" -c`
      SEC_LFTO=`cat ${SEC} | grep -e "${MM}${DD}" | grep -e "logfile turned over" -c`             
      HTP_LFTO=`cat ${HTP} | grep -e "${MM}${DD}" | grep -e "logfile turned over" -c`             
      
      echo "Subject: `hostname` nightly log report"   
      echo "Content-type: text/html"
      echo ""
      echo ""
      echo "<P>`date | awk '{print $1 ",", $2, $3 ",", $6, "at", $4, $5}'`"
      
      echo "<P>System log messages for today:"
      echo "<BLOCKQUOTE><PRE>"
      if [ ${MSG_LFTO} -gt 0 ]; then
              ${UNZIPPROG} ${MSG}.${OLD}.${ZIP}
              cat ${MSG}.${OLD} | grep -e "${MM}${DD}" | grep -e "last message repeated" -v
              ${ZIPPROG} ${MSG}.${OLD}
      fi
      cat ${MSG} | grep -e "${MM}${DD}" | grep -e "last message repeated" -v
      echo "</PRE></BLOCKQUOTE>"
      
      echo "Security log messages for today:"
      CTR2=0
      CTR4=0
      if [ ${SEC_LFTO} -gt 0 ]; then
              ${UNZIPPROG} ${SEC}.${OLD}.${ZIP}
              CTR2=`cat ${SEC}.${OLD} | grep -e "${MM}${DD}" | grep -e "255.255.255.255" -c`
              CTR4=`cat ${SEC}.${OLD} | grep -e "${MM}${DD}" | grep -e "ICMP:8" -c`     
      fi
      CTR1=`cat ${SEC} | grep -e "${MM}${DD}" | grep -e "255.255.255.255" -c`
      CTR3=`cat ${SEC} | grep -e "${MM}${DD}" | grep -e "ICMP:8" -c` 
      echo "<BLOCKQUOTE><PRE>"
      echo "<I> * $(( ${CTR1} + ${CTR2} )) broadcast messages not included</I>"
      echo "<I> * $(( ${CTR3} + ${CTR4} )) inbound ping requests not included</I><BR>"                       
      if [ ${SEC_LFTO} -gt 0 ]; then
              cat ${SEC}.${OLD} | grep -e "${MM}${DD}" | grep -e "255.255.255.255" -v | grep -e "ICMP:8" -v | grep -e "last message repeated" -v
              ${ZIPPROG} ${SEC}.${OLD}
      fi
      cat ${SEC} | grep -e "${MM}${DD}" | grep -e "255.255.255.255" -v | grep -e "ICMP:8" -v | grep -e "last message repeated" -v
      echo "</PRE></BLOCKQUOTE>"
      
      echo "<P>Apache error messages for today:"
      echo "<BLOCKQUOTE><PRE>"
      if [ ${HTP_LFTO} -gt 0 ]; then
              ${UNZIPPROG} ${HTP}.${OLD}.${ZIP}
              cat ${HTP}.${OLD} | grep -e "${MM}${DD}"
              ${ZIPPROG} ${HTP}.${OLD}
      fi
      cat ${HTP} | grep -e "${MM}${DD}"
      echo "</PRE></BLOCKQUOTE>"
      
      
      

    2. Edit /etc/crontab:

      # Nightly status report
      59   23   *   *   *   root   /usr/local/bin/nitestat | sendmail root




http://www.mostgraveconcern.com/freebsd/
Questions or Comments? Contact Us...




Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.