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