This is the first post in a long time. Recently, I'm playing with ubuntu mate installed on gpd-micropc.
I was looking for a way to automatically get the operation log in the terminal. At first I thought I should write a script command in .bashrc, but it doesn't seem to work. .. I found various articles that I searched for and that were helpful. How do I log all input and output in a terminal session?
ubuntu-mate installed on gpd micropc
OS: Ubuntu 19.10 eoan
Kernel: x86_64 Linux 5.3.0-40-generic
Shell: bash
DE: MATE 1.22.2
CPU: Intel Celeron N4100 @ 4x 2.4GHz
GPU: Mesa DRI Intel(R) UHD Graphics 600 (Geminilake 2x6)-
Since the log will be output with the logger
command, create a configuration file below
vim /etc/rsyslog.d/bash.conf
/etc/rsyslog.d/bash.conf
local6.* /var/log/commands.log
.bashrc
Add the following to .bashrc
under the home directory of the user whose operation log is to be acquired.
vim /home/hoge(Target user)/.bashrc
/home/hoge(Target user)/.bashrc
whoami="$(whoami)@$(echo $SSH_CONNECTION | awk '{print $1}')"export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$whoami [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
Restart the rsyslog service
systemctl restart rsyslog.service
Create a config file to rotate daily with logrotate.d
vim /etc/logrotate.d/commands
/etc/logrotate.d/commands
/var/log/commands.log*
{
»-rotate 7
»-daily
»-dateext
»-missingok
»-notifempty
»-compress
»-postrotate
»-»-/usr/lib/rsyslog/rsyslog-rotate
»-endscript
»-su root root
}
Read .bashrc
source .bashrc
Confirm that the file is created under / var / log
as shown below.
ls -la /var/log/commands.log*
-rw-r-----1 syslog adm 4753 March 15 19:34 /var/log/commands.log
/var/log/commands.log
Mar 15 19:34:29 hoge hoge: hoge@export [3457]: 2020-03-15 19:34:29 cd [0]
Mar 15 19:34:39 hoge hoge: hoge@export [3457]: 2020-03-15 19:34:37 source .bashrc [0]
Mar 15 19:36:56 hoge hoge: hoge@export [3457]: 2020-03-15 19:36:56 ls -la /var/log/commands.log* [0]
I'm wondering if I can logrotate. .. After that, I want the output like the script command. ..
Recommended Posts