我有这个问题。 (编写“your_username.sh”脚本以在每次注销时创建一个文本文件。该文件应 包含您在 session 期间执行的所有语句。文本文件的名称应具有以下命名模式“Statements-20191104.0225.txt”(20191104 代表日期,0225 代表时间)。所有文件应存储在 ~/MyStatements 目录。)
我创建 sh 脚本并在 .bash_logout 中调用它。 此脚本创建一个文件并尝试将所有历史记录保存在其中
#!/bin/bash
currentDateTime=$(date +"%Y%m%d.%k%M")
fileName="Statements-$currentDateTime"
touch ~/MyStatements/$fileName
echo $currentDateTime
echo $fileName
history -a "~/MyStatements/$fileName"
history -a newFile.text
在“MyStatements”文件夹中创建了一个新文件,但该文件不包含任何数据
最佳答案
尝试重定向你的输出:
history -a > ~/MyStatements/$fileName
history -a > newFile.text
关于linux - 写入用户在 session 期间执行它的所有语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56477119/