python - Centos 7-flask 授予查看其他用户的 bash 历史记录的权限

标签 python linux bash centos7

我定义了一个返回特定用户最后命令的函数。这是代码:

def user_commands(user):
    line = "/home/"+user+"/.bash_history"
    commands = Popen([ "tail", line], stdout=PIPE, stderr=PIPE).communicate()[0].split('\n')
    return commands

但它只适用于我的用户 python

enter image description here

如果我使用其他用户,它不会显示命令列表。

enter image description here

我认为是因为它需要权限才能查看其他用户的 bash_history。如果我希望它适用于所有用户,我该怎么办。

最佳答案

这听起来像是权限问题。确保运行脚本的用户有权访问 bash 历史文件。

快速而肮脏的答案是以 root 身份运行脚本。

更好的想法可能是运行 cron 作业来收集所需的信息并将其放置在脚本可访问的目录中。

关于python - Centos 7-flask 授予查看其他用户的 bash 历史记录的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43577993/

相关文章:

python - 安装tensorflow时找不到版本

linux - 我们如何测量 Amazon ECS/Ec2 实例的 vCPU 使用率?

linux - 查找包含非打印字符(空字节)的文件

python - 如何做简单、可靠的网络消息传递?

python - 转换为 pandas 数据帧时保留 R 数据帧索引值

python - 使用 numpy 计算条纹

linux - 使用引入的名称创建文件的 Bash 脚本

python - 迭代文件以查找字符串并输出信息

linux - 暂停后在 Xorg 环境中恢复键盘设置

bash - 在 bash "for file in $list"构造中一次取两个