⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logevents.sh

📁 一本完整的描述Unix Shell 编程的工具书的所有范例
💻 SH
字号:
#!/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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -