crontab运行shell脚本,将用户历史记录写入日志文件
我编写以下shell脚本:crontab运行shell脚本,将用户历史记录写入日志文件,shell,crontab,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 * * *
#!/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
不要在crontab脚本中使用
~
。相反,请使用完整路径。另外,在cron表达式中提供一个二进制文件。请看中的“调试crontab”