Configuration of the CRON

Asked

Viewed 37 times

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.

  • More details about cron fields here: https://answall.com/questions/124518/70

  • Wouldn’t it be 1min? the first * of cron commands is not minutes?

  • On the link you sent is there, pointing to the first * as minute 0-59

  • [minutes] [hours] [days of the month] [month] [days of the week] [user] [command]

  • In case I want to put every 5 minutes I would have to do */5?

  • 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)

  • Started working, thanks is running every minute

  • 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.

  • Is this way * * * * * php arquivo.php for me to rotate every 5m would be put */5 * * * * php arquivo.php ?

  • 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)

  • Yes, it’s running properly now, only every 1 m, to run every 5 is like I did there?

  • 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.

  • 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.

  • 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.

  • 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?

  • 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.

  • 1

    I’ll leave it here so you can do that, thanks again for the help.

Show 13 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.