Bash command log ¸¸µé±â

   Á¶È¸ 11189   Ãßõ 1    

https://www.ehostidc.co.kr/ (536)
https://www.ehostidc.co.kr/cscenter/consulting.php (524)

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
2020-01   14860   ¸¸¼®±º
2020-07   14872   ÇÁ·Î½Ã¾Æ
2014-10   14937   witbox
2020-12   14951   ¹Ú¹®Çü
2020-02   14955   ÅëÅë9
2025-02   14966   ¶Öº¸²Ù
2015-07   15009   ÁÖ¿µÁø¿µ¾Æºü
2021-03   15021   ³ª¿ì¼Ò·¡
2022-03   15034   µö·¯´×¼­¹ö
2015-01   15045   ȲÁø¿ì
2023-12   15046   ÇѲ¿Çª
2016-01   15070   ¸¸¼®±º
2016-06   15074   ¹«¾Æ
2022-01   15083   ocarina
2014-02   15088   ±è¿µÀÛ
2016-06   15164   ¹«¾Æ
2021-12   15180   friz
2020-05   15203   ³«¿±À̽½1
2016-02   15262   Psychophysi¡¦
2022-04   15265   ±èȲÁß