zoukankan      html  css  js  c++  java
  • HPUX 只取syslog.log当前三天的信息

    LOG_DAYS=1
    todays_date=`date +%m:%d:%Y`
    current_date=`echo $todays_date | sed 's/://g'`
    day=`echo $todays_date | cut -f 2 -d ":"| sed 's/^0//g'`
    month=`echo $todays_date | cut -f 1 -d ":"| sed 's/^0//g'`
    year=`echo $todays_date | cut -f 3 -d ":"`
    case $LOG_DAYS in
    *[!0-9]* | ???* | 3? | 29) printf -u2 "Invalid input " ; exit 2;;
    esac
    tday=$day
    tmonth=$month
    tyear=$year
    day=$((day - LOG_DAYS))
    if (( day <= 0 )) ; then
    month=$((month - 1))
    if (( month == 0 )) ;then
    year=$((year - 1))
    month=12
    fi
    days=`/usr/bin/cal $month $year`
    xday=`echo $days | awk '{print $NF}'`
    day=$((xday + day))
    fi
    if (( ${#day} == 2 ));then
    day=`echo $day | sed 's/^[1-9]{1}/ &/'`
    else
    day=`echo $day | sed 's/^[1-9]{1}/ &/'`
    fi
    if (( ${#tday} == 2 ));then
    tday=`echo $tday | sed 's/^[1-9]{1}/ &/'`
    else
    tday=`echo $tday | sed 's/^[1-9]{1}/ &/'`
    fi

    month=`cal $month $year | head -n 1 | cut -c 4-6`
    tmonth=`cal $tmonth $year | head -n 1 | cut -c 4-6`

    grep -e "$month$day" -e "$tmonth$tday" /var/adm/syslog/syslog.log | grep -v -e "sshd" -e "ftpd" -e "su:" -e "ETDirect" -e "inetd"

  • 相关阅读:
    iOS exit(0); 直接退出程序
    友盟推送简单调用
    KxMenu下拉菜单
    打开相册另类写法
    简洁调用字号
    十六进制颜色宏
    Swift定义单例
    不要在初始化方法和dealloc方法中使用Accessor Methods
    copyin函数
    c语言中的赋值
  • 原文地址:https://www.cnblogs.com/zlg88/p/5852893.html
Copyright © 2011-2022 走看看