logevents.sh

来自「一本完整的描述Unix Shell 编程的工具书的所有范例」· Shell 代码 · 共 68 行

SH
68
字号
#!/bin/bash# logevents.sh, by Stephane Chazelas.# Event logging to a file.# Must be run as root (for write access in /var/log).ROOT_UID=0     # Only users with $UID 0 have root privileges.E_NOTROOT=67   # Non-root exit error.if [ "$UID" -ne "$ROOT_UID" ]then  echo "Must be root to run this script."  exit $E_NOTROOTfi  FD_DEBUG1=3FD_DEBUG2=4FD_DEBUG3=5# Uncomment one of the two lines below to activate script.# LOG_EVENTS=1# LOG_VARS=1log()  # Writes time and date to log file.{echo "$(date)  $*" >&7     # This *appends* the date to the file.                              # See below.}case $LOG_LEVEL in 1) exec 3>&2         4> /dev/null 5> /dev/null;; 2) exec 3>&2         4>&2         5> /dev/null;; 3) exec 3>&2         4>&2         5>&2;; *) exec 3> /dev/null 4> /dev/null 5> /dev/null;;esacFD_LOGVARS=6if [[ $LOG_VARS ]]then exec 6>> /var/log/vars.logelse exec 6> /dev/null               # Bury output.fiFD_LOGEVENTS=7if [[ $LOG_EVENTS ]]then  # then exec 7 >(exec gawk '{print strftime(), $0}' >> /var/log/event.log)  # Above line will not work in Bash, version 2.04.  exec 7>> /var/log/event.log        # Append to "event.log".  log                                      # Write time and date.else exec 7> /dev/null                  # Bury output.fiecho "DEBUG3: beginning" >&${FD_DEBUG3}ls -l >&5 2>&4                       # command1 >&5 2>&4echo "Done"                                # command2 echo "sending mail" >&${FD_LOGEVENTS}   # Writes "sending mail" to fd #7.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?