问题
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