Bash command log ¸¸µé±â

   Á¶È¸ 11489   Ãßõ 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 26/29
2023-12   12008   inquisitive
2025-10   11975   ¹Ú¹®Çü
2020-08   11964   Tails
2020-10   11818   ÀÎõIº£¸®
2021-10   11729   ¼ÛÁÖȯ
2018-11   11717   user
2021-07   11709   ¹Ú¹®Çü
2019-10   11700   °£Àå°ÔÀå
2019-11   11685   °í°í´Ù
2021-02   11670   ¶Öº¸²Ù
2021-02   11490   µö·¯´×¼­¹ö
2020-10   11454   wwwdjw
2014-02   11452   ºü½Ã¿Â
2020-08   11427   tedious
2022-01   11400   °£Àå°ÔÀå
2021-06   11360   È­Á¤Å¥»ï
2023-12   11345   inquisitive
2020-12   11335   Äðº¸ÀÌ
2022-01   11324   ¹Ú¹®Çü
2019-02   11270   Á¶ÀÌÄÄÁ¤°ü½Ä