append to /etc/profile root@moonx:/tmp/dbasky/moonx# cat /etc/profile
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` "
append to /etc/profile
root@moonx:/tmp/dbasky/moonx# cat /etc/profile
...
PS1="`whoami`@`hostname`:"'[$PWD]'
history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /tmp/dbasky ]
then
mkdir /tmp/dbasky
chmod 777 /tmp/dbasky
fi
if [ ! -d /tmp/dbasky/${LOGNAME} ]
then
mkdir /tmp/dbasky/${LOGNAME}
chmod 300 /tmp/dbasky/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y-%m-%d_%H:%M:%S"`
export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky.$DT"
chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null
moonx@moonx:/tmp/dbasky$ sudo -i
root@moonx:~# cd /tmp/dbasky/moonx/
root@moonx:/tmp/dbasky/moonx# ls
192.168.5.45 dbasky.2019-11-22_11:37:27
192.168.5.45 dbasky.2019-11-22_11:41:55
root@moonx:/tmp/dbasky/moonx# cat 192.168.5.45 dbasky.2019-11-22_11:41:55
ls
echo $HISTFILE
cat /etc/profile
root@moonx:/tmp/dbasky/moonx#