I have a cron which runs daily (at midnight) and modifies a few database tables of a web application.
I want to make sure it worked OK before letting users continue to use the application. Currently some functions in the app. are temporarily disabled for 1 minute.
Anyway since I’m on a shared server I cannot be sure the cron will execute without errors. There could be a database connection error etc. So I need to check if the cron executed.
It could be checked at PHP level and I have one solution in my mind.
How would you check whether a cron is executed without errors in this situation?
How do you let the app know whether the cron was successful? I ask because I don’t see how that would work. As far as I can see there are two options with both the same drawback.
Via the database
Set some value in a database to true or false, but if the cron was not successful because no database connection could be made then you can also not put in the database that the cron did not work correctly and the app would not know the when the cron didn’t run correctly.
Via a file
Write a value to a file indicating if the cron worked correctly. If the file is for some reason not writable (HDD full, wrong permissions) the app would not know when the cron didn’t run correctly.
Simply updating (at the end of the script) and checking the timestamp, as I mentioned before. I think I won’t need exit status for now. If the database connection fails the timestamp cannot be updated as it’s stored in the same database.