Hi in this tip I will show you how we can run CakePHP 3 shell script in the background after a specific interval of time using shell script. I hope you already know how to create a shell in CakePHP 3. Now in here, I can create a new file outside CakePHP 3 project and name as cakeshell.sh. Now you can paste below code on that file.

#!/bin/bash
while true; do
    begin=`date +%s`
    /var/www/html/e-chats.com/bin/cake SHELL_NAME SHELL_METHOD
    end=`date +%s`
    if [ $(($end - $begin)) -lt 5 ]; then
        sleep $(($begin + 5 - $end))
    fi
done

In the above code, you need to replace SHELL_NAME and SHELL_METHOD with your shell name and method. This code run shell script after 5 seconds of interval you can set interval according to your need. To run this script you need to login to your terminal and after that, you need to enter command like this

cd /var/www/html/myshell_folder
./cakeshell.sh

Now your shell starts running. Hope this post helps you thanks.

Happy coding:).