Insert date-time in php cronjob

Thanks in advance for any help!

I have a php script that I have put in a cronjob.
However, all the data is lumped into a log file. I’d like to have it entered with date-time on each line.
The cronjob is:

#  Section for Appointment calendar
# run sms reminders hourly
0 8-17 * * * /usr/bin/php /var/www/html/modules/mod_sv_reminders_sms/reminders_cron_sms.php >> /var/log/apptbooking.log 2>&1

It works well, but really unreadable as all data in log file is tossed in.

It is a php script that searches a database for all appointments and sends a text message reminder. I added sending to log file so I can monitor any errors.

I tried amending two ways, neither work:

/usr/bin/php date +%d-%m-%y/%H:%M:%S /var/www/html/modules/mod_sv_reminders_sms/reminders_cron_sms.php >> /var/log/apptbooking.log 2>&1

/usr/bin/php /var/www/html/modules/mod_sv_reminders_sms/reminders_cron_sms.php |ts ‘[%Y-%m-%d %H:%M]’ >> /var/log/apptbooking.log 2>&1

If someone can point me to a solution, or share how to fix, I’d really appreciate it

Well, you can’t redirect output with ease. Super complicated.

Normally, you just rewrite CRON JOB to save the output instead of display it.
A CRON JOB is usually just a PHP file like any other website page.
Alter it to store the data output into your database log table.

Hope that makes sense…

Thank you for the response. However, I have no idea what you said ( sigh). Could you explain another way?

This is a PHP file. A standard program that runs on the server. If you edit it, you will be able to see at various places inside the file, it echo’s or print’s out data. That would be where you create a log file and then you could save it into a database tables. If you just redirect the outputs using the >> option, the data outputted from the PHP program gets stored into a file called apptbooking.log. If you want to, you could create a simple PHP program to move that into the database, but, it really depends what you want done with the outputs.

I would assume you want to keep the outputs placed into a database each time the PHP program runs and then you could have the data at hand to search or display as needed. If the CRON job is really a SMS system, it most likely sends out texts to users.

Perhaps you should give us some further info on what these logs create or look like and what you want to do with them. We can help, but, your final results needed is not clear.

Its easy just modify your script reminders_cron_sms.php to save date time and output and append the result to a log file on your hard disk . so every time the job runs it does its stuff and saves a log .

Hey, Expert? Didn’t I just say that?

1 Like

Ah great minds think alike , now he has a detailed answer and a sumarized one 2 answers that point to good solutions :slight_smile: yay

Sponsor our Newsletter | Privacy Policy | Terms of Service