Article excerpt from:
http://blog.csdn.net/lixiaohuiok111/article/details/34428161
http://blog.csdn.net/lixiaohuiok111/article/details/34428161 first we give the OPT directory a write permission to sudo chmod a+w/opt then execute source/etc/ Profile and then exit the machine, when you re-enter the/opt/history below there will be a file generated by the admin.History
And then we'll change the permissions back to write scripts to use Ansible batch deployment to other machines
- #!/bin/bash
sudo chmod a+w/opt
Cat <<eof>>/etc/profile
#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/opt/history]
then
mkdir/opt/history
chmod 777/opt/< Span class= "Highlight" >history
fi
if [!-d/opt/history/\$ {LOGNAME}]
then
mkdir/opt/history/\${logname}
chmod 300/opt/history/\${logname}
fi
export histsize= 4096
export histtimeformat= "%F%T $USER _ip:\ ' whoami\ '"
export histfile= "/opt/history/\${logname}. history "
chmod 600/opt/history/* history* 2>/dev/null
eof
source/etc/profile
sudo chmod o-w/opt
#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/opt/History]
Then
mkdir/opt/History
chmod 777/opt/History
Fi
if [!-d/opt/History/${logname}]
Then
mkdir/opt/History/${logname}
chmod 300/opt/History/${logname}
Fi
Export histsize=4096
Export histtimeformat= "%F%T $USER _ip: ' WhoAmI '"
Export histfile= "/opt/history/${logname}. History
chmod 600/opt/history/*history* 2>/dev/null
The history command shows the detail time