Monday, January 29, 2024

[SOLVED] Cron Job for call a PHP program

Issue

I need a create a cron job to call a PHP program, when I will call a PHP program ,I need to send a date parameter as well.

The below code working fine in the linux terminal.

php execute_attendance.php 10/12/2022.

I have created cron job but it's not running.....

*/15 * * * * unb /opt/unb/bin/execute_attendance date +%F --date="15 days ago"> /dev/null 2>&1

date +%F --date="15 days ago" this code is returning sysdate - 15,it working fine with linux terminal.


Solution

you can wrap this into bash script like:

#! /bin/bash
d=$(date +%F --date="15 days ago")
php execute_attendance.php "$d"

and after this add bash script call to cron

*/15 * * * * unb your_bash_script.sh > /dev/null 2>&1

another way is move date calculation within php script



Answered By - Slava Rozhnev
Answer Checked By - Pedro (WPSolving Volunteer)