Bash script that executes php file every 5 seconds

后端 未结 6 1959
孤街浪徒
孤街浪徒 2020-12-22 06:09

Bash script:

$ cat test.sh
#!/bin/bash
while true
do
 /home/user/public_html/website.com/test.php
 sleep 5
done

Im trying to call it with c

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-22 06:57

    Below code I've used linux & cent os servers its working for me

    Step 1 => Within this path /usr/bin create autocron.sh file -> vim autocron.sh

    Step 2 => After creating autocron.sh file -> Put this code within autocron.sh file while true; do begin=date +%s; php executablefile.php; end=date +%s; if [ $(($end - $begin)) -lt 5 ]; then sleep $(($begin + 5 - $end)); fi; done -> Example excutable PHP file name & .sh file shouble be the same .

    Step 3 => After that save that autocron.sh file

    Step 4 => Give the permissions for autocron.sh file -> chmod +x autocron.sh

    Step 5 => And also give the permissions for PHP file -> chmod +x PHP file location (executablefile.php)

    Step 5 => This command will runs the .sh file in background process even terminal was closed -> nohup sh autocron.sh&

提交回复
热议问题