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

标签 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

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

最佳答案

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

*/2 * * * *  USERNAME  /bin/bash /home/user/history.sh

关于shell - crontab 运行将用户历史记录写入日志文件的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27247946/

相关文章:

linux - 测试 Linux 中是否安装了驱动器

shell - shell 脚本中的 SQOOP 导出失败

shell - 在 linux 中从 Web 浏览器执行 shell 脚本

bash -/bin/sh : 1: Bad substitution Makefile

python - celery -Django : Celery vs django management commands

python - ${PYTHON :-python} in shell script and how to change 的含义

没有 crontab -e 的 crontab

linux - Crontab 无法正常工作

php - Crontab:PHP Wget 或 Curl

amazon-s3 - Gitlab综合: Delete backup from Amazon S3