서버 root 홈디렉토리에 .log_history 디렉토리 생성




.bash_profile 에 아래 내용추가






export PS1="\`echo -en \| \\# \|$(tty)\|\t\| >> $HOME/.log_history/history_$(date '+%y%m%d')




echo -en $(date '+%y%m%d')\|$SSH_CLIENT\| >> $HOME/.log_history/history_$(date '+%y%m%d')






history |tail -n 1 >> $HOME/.log_history/history_$(date '+%y%m%d')




echo '[\u@\h \W]\\$ '\`"










그러면 히스토리 확실하게 남길 수 있음






그다음 /etc/profile 에 






NOW=$(date +%Y-%m-%d-%H:%M)


mkdir -p /root/.log_history/$NOW




TTY=`echo $(tty) | awk -F / '{print $3$4}'`


script -q /root/.log_history/$NOW/$TTY




이거 넣어두면 




/root/.log_history/%TTY 에 그사람(pts0,1등등)이 입력했던 명령어, 그 명령어의 결과값까지 저장됨




근데...script 명령어가 완전 실시간이 아니라 한 10초정도 뒤에 입력되는듯 ? exit 명령어를 넣어주면 전부 저장이 되는데 씨큐어,푸티를 종료하는등의 세션을 그냥 꺼버리면 마지막 10초정도는 저장이 안되는듯

+ Recent posts