Implemented snapshot execution algorithm on my site. It works as follows: when a search engine robot requests one of the search engines, the algorithm checks the date of creating the snapshot file. If the file is out of date (30 days have passed since its creation), PHP runs the exec() command with the NodeJS script, which updates the snapshot file. The problem is that Noda spends 3-5 seconds creating snapshots, which the robot doesn't like at all. Therefore, the only way to fix this, which I was able to come up with, is to give the robot the current snapshot, and then run the asynchronous delayed execution of the script. That is, just return the robot snapshot (satisfying its requirement for page load speed). Then make an entry in the crontab, they say, you need to execute the command to execute a snapshot of the page of such and such a number at a certain time on behalf of the user www-data. Now the question is: first, can crontab execute commands not only at a certain interval, but at a specified time and date? Secondly, will crontab perform the task under the user www-data? And thirdly, can crontab delete a record after it is executed, or will you have to open a file through php, look for the necessary record and erase it? Thank.

  • without losing the essence, the text of the question can be reduced at least five times. which I recommend you do. - aleksandr barakin
  • @alexanderbarakin I always try to ask my questions as clearly as possible and deployed, so that whoever reads it clearly understands what I am going to do and why I can give me the same clear and detailed answer. - JamesJGoodwin

1 answer 1

  1. Is crontab able to execute commands not only at a certain interval, but at a specified time and date?

    Of course not. crontab is a file format understood by cron .

    addition: the format of the crontab file allows you to specify the time, day of the week, day of the month, month.

  2. Does crontab perform the task under the user www-data?

    see previous paragraph.

    with the addition: the cron program usually works as the root , therefore it can start processes with lower privileges.

  3. can crontab delete a record after it is executed?

    see first paragraph.

    with the addition: no, the cron program does not include any manipulations with crontab files.

  4. Or do you have to open a file through php, search for the necessary entry and erase it?

    a much better solution would be to run your script periodically, which will do the necessary work (with snapshots, or whatever else you need).