crontab运行shell脚本,将用户历史记录写入日志文件

时间:2014-12-02 11:09:59

标签: shell crontab

我编写了以下shell脚本:

#!/bin/bash
HISTFILE=~/.bash_history
set -o history
file=$(date "+%Y_%m_%d_%H_%M_%S").txt
history  > /home/sandipon/$file
cat  /home/user/$file
sshpass -p my_password scp  /home/user/$file host:/home/test/$file

由cron安排:

*/2 * * * *  /home/user/history.sh

但它提供了一个空白文件。

1 个答案:

答案 0 :(得分:1)

来自fedorki的评论是正确的。 此外,您应该在crontab文件中添加用户名(如果您使用“/ etc / crontab”) 例如:

*/2 * * * *  USERNAME  /bin/bash /home/user/history.sh
相关问题