Crontab script not generating text file [closed]

落爺英雄遲暮 提交于 2020-07-16 06:14:08

问题


Here is my crontab entry:

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

Here is the script, test_thing.sh:

echo "asdf" >> ./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.

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.

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

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


回答1:


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.

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


来源:https://stackoverflow.com/questions/34868231/crontab-script-not-generating-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!