Bash command log ¸¸µé±â

   Á¶È¸ 11488   Ãßõ 1    

https://www.ehostidc.co.kr/ (566)
https://www.ehostidc.co.kr/cscenter/consulting.php (551)

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
2021-09   29914   µö·¯´×¼­¹ö
2011-11   29683   ¹Ú
2014-04   29301   dydans
2022-08   29191   ÄíÀö
2022-08   29100   ¹Ú¹®Çü
2015-01   29077   ȲÁø¿ì
2015-09   28940   ÁÒ¯
2016-07   28680   ¹é¸¸½º¹°Çϳª
2023-03   28450   oht993
2022-03   28435   °¨ÀÚ°¨ÀÚ
2015-06   28420   stone92±è°æ¹Î
2019-07   28380   µö·¯´×¼­¹ö
2022-05   28332   ocarina
2022-07   28195   µö·¯´×¼­¹ö
2018-02   28138   ¹«¾Æ
2017-07   27929   stone92±è°æ¹Î
2022-06   27835   µö·¯´×¼­¹ö
2014-07   27632   ºÐ³ëÀÇ´Ù¿îÈú
2016-08   27625   ¹Ì³ª¸®³ª¹°
2022-08   27479   °¨ÀÚ°¨ÀÚ