标签归档:export

centos history显示命令执行时间、执行用户,执行IP

1.在/etc/profile的最后添加如下部分:

USER_IP=`who -u am i 2>/dev/null| awk ‘{print $NF}’|sed -e ‘s/[()]//g’`  
export HISTTIMEFORMAT=”[%F %T][`whoami`][${USER_IP}] ” 

重载:source /etc/profile

export HISTTIMEFORMAT


测试一下:#history 

    1  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
    2  [2016-12-08 22:53:49][root][192.168.1.20] init 3
    3  [2016-12-08 22:53:49][root][192.168.1.20] df
    4  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/resolv.conf 
    5  [2016-12-08 22:53:49][root][192.168.1.20] ll
    6  [2016-12-08 22:53:49][root][192.168.1.20] df
    7  [2016-12-08 22:53:49][root][192.168.1.20] df -h
    8  [2016-12-08 22:53:49][root][192.168.1.20] ll
    9  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   10  [2016-12-08 22:53:49][root][192.168.1.20] netstat -npt
   11  [2016-12-08 22:53:49][root][192.168.1.20] cd /etc/sysconfig/
   12  [2016-12-08 22:53:49][root][192.168.1.20] ll
   13  [2016-12-08 22:53:49][root][192.168.1.20] cd network
   14  [2016-12-08 22:53:49][root][192.168.1.20] cd network-scripts/
   15  [2016-12-08 22:53:49][root][192.168.1.20] ll
   16  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   17  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   18  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/fstab 
   19  [2016-12-08 22:53:49][root][192.168.1.20] \df
   20  [2016-12-08 22:53:49][root][192.168.1.20] df
   21  [2016-12-08 22:53:49][root][192.168.1.20] umount tmpfs
   22  [2016-12-08 22:53:49][root][192.168.1.20] df
   23  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   24  [2016-12-08 22:53:49][root][192.168.1.20] dmesg 
   25  [2016-12-08 22:53:49][root][192.168.1.20] df
   26  [2016-12-08 22:53:49][root][192.168.1.20] ll
   27  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   28  [2016-12-08 22:53:49][root][192.168.1.20] ifup eth0
   29  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   30  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   31  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   32  [2016-12-08 22:53:49][root][192.168.1.20] ifconifg
   33  [2016-12-08 22:53:49][root][192.168.1.20] ls
   34  [2016-12-08 22:53:49][root][192.168.1.20] reboot ;exit
   35  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   36  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   37  [2016-12-08 22:53:49][root][192.168.1.20] dmesg 
   38  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   39  [2016-12-08 22:53:49][root][192.168.1.20] netstat -nlpt
   40  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   41  [2016-12-08 22:53:49][root][192.168.1.20] exit
   42  [2016-12-08 22:53:49][root][192.168.1.20] shutdown -P now
   43  [2016-12-08 22:53:49][root][192.168.1.20] ifconifg
   44  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   45  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.1
   46  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.3
   47  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   48  [2016-12-08 22:53:49][root][192.168.1.20] cd /etc/sysconfig/network-scripts/
   49  [2016-12-08 22:53:49][root][192.168.1.20] ll
   50  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   51  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   52  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   53  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   54  [2016-12-08 22:53:49][root][192.168.1.20] route -a
   55  [2016-12-08 22:53:49][root][192.168.1.20] route -n
   56  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   57  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   58  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   59  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   60  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   61  [2016-12-08 22:53:49][root][192.168.1.20] iptables-save
   62  [2016-12-08 22:53:49][root][192.168.1.20] iptables -F
   63  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   64  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   65  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   66  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   67  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   68  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   69  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   70  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   71  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   72  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   73  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   74  [2016-12-08 22:53:49][root][192.168.1.20] ping 192.168.1.100
   75  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   76  [2016-12-08 22:53:49][root][192.168.1.20] ping v.qq.com
   77  [2016-12-08 22:53:49][root][192.168.1.20] ifconfig
   78  [2016-12-08 22:53:49][root][192.168.1.20] vi ifcfg-eth0 
   79  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/network restart
   80  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   81  [2016-12-08 22:53:49][root][192.168.1.20] dmesg 
   82  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   83  [2016-12-08 22:53:49][root][192.168.1.20] shutdown -p now
   84  [2016-12-08 22:53:49][root][192.168.1.20] shutdown -P now
   85  [2016-12-08 22:53:49][root][192.168.1.20] reboot
   86  [2016-12-08 22:53:49][root][192.168.1.20] df
   87  [2016-12-08 22:53:49][root][192.168.1.20] dmesg 
   88  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   89  [2016-12-08 22:53:49][root][192.168.1.20] netstat -nlpt
   90  [2016-12-08 22:53:49][root][192.168.1.20] cd /usr/local/
   91  [2016-12-08 22:53:49][root][192.168.1.20] ll
   92  [2016-12-08 22:53:49][root][192.168.1.20] rz -dey
   93  [2016-12-08 22:53:49][root][192.168.1.20] yum install -y lrzsz telnet tcpdump traceroute vmstat sysstat rsync mail bind-utils
   94  [2016-12-08 22:53:49][root][192.168.1.20] rz -dey
   95  [2016-12-08 22:53:49][root][192.168.1.20] tar -zxvf services.20160816.tgz 
   96  [2016-12-08 22:53:49][root][192.168.1.20] df -h
   97  [2016-12-08 22:53:49][root][192.168.1.20] ll
   98  [2016-12-08 22:53:49][root][192.168.1.20] w
   99  [2016-12-08 22:53:49][root][192.168.1.20] df -h
  100  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/sysconfig/iptables
  101  [2016-12-08 22:53:49][root][192.168.1.20] /etc/init.d/iptables restart
  102  [2016-12-08 22:53:49][root][192.168.1.20] w
  103  [2016-12-08 22:53:49][root][192.168.1.20] df
  104  [2016-12-08 22:53:49][root][192.168.1.20] df -h
  105  [2016-12-08 22:53:49][root][192.168.1.20] dmesg 
  106  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/profile
  107  [2016-12-08 22:53:49][root][192.168.1.20] exit
  108  [2016-12-08 22:53:49][root][192.168.1.20] history 
  109  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/profile
  110  [2016-12-08 22:53:49][root][192.168.1.20] exit
  111  [2016-12-08 22:53:49][root][192.168.1.20] history 
  112  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/profile
  113  [2016-12-08 22:53:49][root][192.168.1.20] exit
  114  [2016-12-08 22:53:49][root][192.168.1.20] w
  115  [2016-12-08 22:53:49][root][192.168.1.20] history 
  116  [2016-12-08 22:53:49][root][192.168.1.20] vi /etc/profile
  117  [2016-12-08 22:53:49][root][192.168.1.20] exit
  118  [2016-12-08 22:53:50][root][192.168.1.20] history