Crontab脚本未生成文本文件 [英] Crontab script not generating text file

查看:286
本文介绍了Crontab脚本未生成文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的crontab条目:

Here is my crontab entry:

* * * * * /home/ec2-user/Test/test_thing.sh

这是脚本test_thing.sh:

echo "asdf" >> ./bla.txt

当我手动运行它时,它会生成"bla.txt"文件.但是,它不会自动使用crontab这样做(在/Test/目录中创建"bla.txt"文件).

When I run it manually, it does generate the "bla.txt" file. However, it does not automatically do so (create the "bla.txt" file within the /Test/ directory) with the crontab.

我还检查了我的/var/log/cron文件,我发现它每分钟执行一次,但是不确定是否正在运行错误.

I have also checked my /var/log/cron file and I see that it is executed every minute, but not sure if it's running into an error or not.

如果重要的话,我将在Amazon ec2服务器(特别是Amazon Linux AMI)上运行它.

If it is important, I am running this on an Amazon ec2 server, specifically the Amazon Linux AMI.

我也做了chmod +x test_thing.sh以确保它是可执行的.

Edits: I have also done chmod +x test_thing.sh to make sure it is executable.

推荐答案

默认情况下,cronjob从主目录运行.因此,如果您以root帐户运行,则应该在/home/ec2-user或/root下看到要创建的文件.

The cronjob runs from home directory by default. So you should see the file to be created under /home/ec2-user or /root if you run it by root account.

如果您需要使用指定路径生成新文件,一种方法是使用@yftse所说的绝对路径.另一种方法是

If you need generate the new file with the nominate path, one way is to use absolute path as @yftse said. The other way is

* * * * * cd /home/ec2-user/Test/; bash /home/ec2-user/Test/test_thing.sh

这篇关于Crontab脚本未生成文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆