Bash command log ¸¸µé±â

   Á¶È¸ 11336   Ãßõ 1    

https://www.ehostidc.co.kr/ (547)
https://www.ehostidc.co.kr/cscenter/consulting.php (543)

1) rsyslog 및 패키지 설치

root@localhost:[~]: yum install -y rsyslog rsyslog-doc -y


2) /etc/profile.d/ 내 스크립트 로그 작성

root@localhost:[~]: vi /etc/profile.d/log.sh

#!/bin/bash

function history_to_syslog {

  declare command;remote=`who am i|awk '{print $5}'`;command=`fc -ln -0|sed 's/\t //'`

  if [ $USER == "root" ];then located="$PWD]#";else located="$PWD]$";fi

  if [ "$command" != "$old_command" ]; then

    logger -p local3.notice -t bash -i "history2syslog: $USER$remote:$located $command"

  fi;old_command=$command

}

trap history_to_syslog DEBUG


3) 별도 파일 생성을 위한 rsyslog 수정

root@localhost:[~]: vi /etc/rsyslog.conf

*.info;mail.none;authpriv.none;cron.none;local3.none                /var/log/messages

local3.notice                                           /var/log/cmd


4) rsyslog 서비스 재시작 및 log 확인

root@localhost:[~]: service rsyslog restart

root@localhost:[~]: tail -f /var/log/cmd







Á¦¸ñPage 9/29
2023-02   36619   µö·¯´×¼­¹ö
2023-02   26988   µö·¯´×¼­¹ö
2020-02   9873   ¸¸¼®±º
2020-02   10956   ȲÁø¿ì
2023-03   22680   ¿ö´Ï´Ô
2016-03   12892   ĵÀ§µå
2020-11   16252   È­Á¤Å¥»ï
2019-05   13303   chobo
2019-07   28217   µö·¯´×¼­¹ö
2023-03   47774   witbox
2013-01   72167   ÀÌÁöÆ÷Åä
2022-01   9628   ¹Ú¹®Çü
2022-01   13230   È­Á¤Å¥»ï
2017-07   26338   ¼¼¹ú½­
2017-07   47588   ¼¼¹ú½­
2017-07   30147   ¼¼¹ú½­
2017-07   246233   ¼¼¹ú½­
2021-01   14175   µö·¯´×¼­¹ö
2018-08   14832   °õÅÊÀ̾ƺü
2017-07   45549   ¼¼¹ú½­