linux执行脚本查找ip,linux 查看ip、用户、时间对应执行的命令
這個需要使用到history命令。可以加數字,返回最近執行的幾條命令。如果不加數字會返回所有的歷史命令。
[[email?protected] ~]# history 20
1015rm stdin.log1016ll1017rm yy1018ll1019 echo ‘hello‘ 1>>echo.log1020ll1021cat echo.log1022 echo ‘world‘ 1>>echo.log1023cat echo.log1024 echo ‘world‘ 1>echo.log1025cat echo.log1026ll1027rm echo.log1028last1029history1030who am i1031clear1032history1033*
1034 history 20
如果需要查看用戶、ip和時間,需要配置linux的變量。
編輯
vim /etc/profile
后面添加變量:
export HISTTIMEFORMAT="%F %T `who am i` "
然后使之生效:
source /etc/profile
[[email?protected] etc]# history 20
1022 2020-02-02 17:03:16 root pts/1 2020-02-02 13:31 (192.168.190.14) echo ‘world‘ 1>>echo.log1023 2020-02-02 17:03:20 root pts/1 2020-02-02 13:31 (192.168.190.14) cat echo.log1024 2020-02-02 17:03:28 root pts/1 2020-02-02 13:31 (192.168.190.14) echo ‘world‘ 1>echo.log1025 2020-02-02 17:03:31 root pts/1 2020-02-02 13:31 (192.168.190.14) cat echo.log1026 2020-02-02 17:09:05 root pts/1 2020-02-02 13:31 (192.168.190.14) ll1027 2020-02-02 17:09:11 root pts/1 2020-02-02 13:31 (192.168.190.14) rm echo.log1028 2020-02-02 17:12:58 root pts/1 2020-02-02 13:31 (192.168.190.14) last1029 2020-02-02 17:14:15 root pts/1 2020-02-02 13:31 (192.168.190.14) history1030 2020-02-02 17:47:12 root pts/1 2020-02-02 13:31 (192.168.190.14) who am i1031 2020-02-02 17:53:15 root pts/1 2020-02-02 13:31 (192.168.190.14) clear1032 2020-02-02 17:53:21 root pts/1 2020-02-02 13:31 (192.168.190.14) history1033* 2020-02-02 17:53:29 root pts/1 2020-02-02 13:31 (192.168.190.14)1034 2020-02-02 17:53:40 root pts/1 2020-02-02 13:31 (192.168.190.14) history 20
1035 2020-02-02 17:55:12 root pts/1 2020-02-02 13:31 (192.168.190.14) last1036 2020-02-02 17:58:23 root pts/1 2020-02-02 13:31 (192.168.190.14) cd /etc1037 2020-02-02 17:58:25 root pts/1 2020-02-02 13:31 (192.168.190.14) ll1038 2020-02-02 17:58:33 root pts/1 2020-02-02 13:31 (192.168.190.14) vim profile1039 2020-02-02 18:01:54 root pts/1 2020-02-02 13:31 (192.168.190.14) source /etc/profile1040 2020-02-02 18:02:03 root pts/1 2020-02-02 13:31 (192.168.190.14) histoty 20
1041 2020-02-02 18:02:10 root pts/1 2020-02-02 13:31 (192.168.190.14) history 20
可以看到多出了,操作時間,用戶,以及操作的ip。
who am i 比較容易理解,就是輸出登入的用戶名,登入時間,以及ip啥的。
那%F %T啥的,其實就是一種格式。這種格式是strftime函數。可以搜索了解下strftime。
原文:https://www.cnblogs.com/chenmz1995/p/12253058.html
總結
以上是生活随笔為你收集整理的linux执行脚本查找ip,linux 查看ip、用户、时间对应执行的命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows运行窗口怎么打开?(Win
- 下一篇: 10.1寸多大(平板电脑10.1英寸有多