logs logged on by login IP record for all Linux users log in to log on for Linux user operations The history is generally viewed through the command histories, but if the important data is deleted due to misoperation, the historical command will not work. So what should be done with historical records? In fact, we can log in through the IP address to record all user login operation history operation! The specific operation is to/etc/the end of the profile configuration file is implemented by adding the following script code: # Historyuser=' WhoAmI ' user_ip= ' Who-u am I2>/dev/NULL| Awk'{print $NF}'|sed-e's/[()]//g'`if["$USER _ip"="" ]; Thenuser_ip=' hostname ' fiif[!-d/usr/local/History ]; Thenmkdir/usr/local/Historychmod777/usr/local/Historyfiif[!-d/usr/local/history/${logname}]; Thenmkdir/usr/local/history/${logname}chmod -/usr/local/history/${logname}fiexport histsize=10000DT= ' Date +"%y-%m-%d_%h:%m:%s"' Export Histfile="/usr/local/history/${logname}/${user}@${user_ip}_history. $DT"chmod -/usr/local/history/${logname}/*history* 2>/dev/null [[email protected] ~]# source/etc/profile[[email protected] ~]# logout# you need to exit the system and login again at/usr /local/history/directory only records [[email protected] ~]# ll/usr/local/history/root/Total usage 12-rw-------1 root root 77 October 09:09 [EMA Il protected]_history.2012-10-11_09:09:12-rw-------1 root root 529 October 09:11 [email protected]_history.2012-10-11_09 : 09:16-rw-------1 root root 187 October 09:12 [email protected]_history.2012-10-11_09:11:26
Log logged in by logging on to all Linux users via login IP