0
I’m trying to run a file in cron, but I’m not getting it. It would have some extra configuration that needs to be done?
[root@ip-172-31-35-95 ec2-user]# crontab -l
1 * * * * php home/cronrelatorio.php 1
1 * * * * echo "Não entre em pânico" > home/test.txt
I played my script and an echo to test, but it does not run, if I play these commands on the terminal in "hand" they run without any problem.
Note: After placing the commands I already restarted cron and tried to do cron by apache user also.
How long did you wait to see if it was working? This cron of yours will only run once an hour.
– Bacco
More details about cron fields here: https://answall.com/questions/124518/70
– Bacco
Wouldn’t it be 1min? the first * of cron commands is not minutes?
– Gustavo Souza
On the link you sent is there, pointing to the first * as minute 0-59
– Gustavo Souza
[minutes] [hours] [days of the month] [month] [days of the week] [user] [command]
– Gustavo Souza
In case I want to put every 5 minutes I would have to do */5?
– Gustavo Souza
It’s one of the ways. Anyway, I edited that post to improve the spelling (instead of minutes, I wrote "in which minutes" to avoid confusion)
– Bacco
Started working, thanks is running every minute
– Gustavo Souza
Make sure you have a blank line at the end of the configuration, and put the full path to the PHP binary to make sure that’s not the problem. If you do a test with an echo, be sure to send the output to a file with permission.
– Bacco
Is this way
* * * * * php arquivo.php
for me to rotate every 5m would be put*/5 * * * * php arquivo.php
?– Gustavo Souza
Do /path/to/o/php /path/to/o/file.php to make sure that the problem is not the path. And watch out for enter at the end of the line. */5 is every 5 (in the case, in the first field, minutes)
– Bacco
Yes, it’s running properly now, only every 1 m, to run every 5 is like I did there?
– Gustavo Souza
For each one normally does not need */1, it would be enough * - now, between us, if you need to run every minute, it may be the case to rethink the architecture of the task. In everyday situations this is not normal.
– Bacco
It is not every 1m, it is every 5m, I put */5 now to do the test and it worked, I do the update both manual and by cron, it is a report I need real data, but I have a calculation in my file that checks whether it has passed 5m from the last hr of update, both by cron and manual, if given the 5m it runs the file, if not it gives an Exit and tries after 5m again.
– Gustavo Souza
Then it gets more interesting. Remember that depending on the case you don’t even need to cron, you can leave a PHP running on an infinite loop (via command line), but with a Sleep in the middle to sleep for a few minutes without occupying the CPU - then you would only use the CRON to test if you didn’t "drop" the script, with more interval. But there it is case by case. Any doubt let us know.
– Bacco
Really? I didn’t know there was such a thing, I will research, thanks for the help! I wouldn’t want to give an answer down there so I can mark it as correct?
– Gustavo Souza
I think it would look very similar to the other, it would be better after someone votes as a duplicate if that solved. Duplicate is not penalty, it is a way for your question to stay always on the site, and to link to each other, helping other users search.
– Bacco
I’ll leave it here so you can do that, thanks again for the help.
– Gustavo Souza