从根和用户配置文件中收集命令历史信息

时间:2017-04-14 21:49:17

标签: linux bash macos shell

我正在编写一个bash脚本来收集Mac OSX端点上的bash和shell命令历史信息。我以root身份运行脚本。这只是更大脚本的一部分。我遇到的问题是它只捕获根配置文件的命令历史信息,并为我提供了当前用户配置文件的相同信息。我知道我可以'猫'所有“_history”文件并将它们输出到一个txt文件,但这并没有给我输出我真正想要的时间戳。

欢迎任何建议。

#!/bin/bash
echo *****************Shell Command history for Root**************** > Shell_History.txt

HISTFILE=~/.sh_history
HISTTIMEFORMAT="%d/%m/%y %T "

set -o history           
history >> Shell_History.txt

echo *****************Bash Command history for Root**************** > Bash_History.txt

HISTFILE=~/.bash_history
HISTTIMEFORMAT="%d/%m/%y %T "

set -o history           
history >> Bash_History.txt


echo *****************Command history for user $USER****************************** > User_History.txt
USER=`users`
HISTFILE=/Users/$USER/.bash_history
HISTTIMEFORMAT="%d/%m/%y %T "
set -o history
history >> User_History.txt

0 个答案:

没有答案