Home > Enterprise >  execute php file from shell script excluding certain time
execute php file from shell script excluding certain time

Time:01-26

I have an Shell script that runs a PHP script every 8 seconds as seen below:

enter code here

#!/bin/bash

while true; do php /var/www/html/folder1/scripts/processtask.php /var/www/html/folder1/app sleep 8; done

enter code here

I need it to continue this way, however I need it to stop running at 2am until 3am then resume after that on a daily basis

CodePudding user response:

You can use cronetab for the same. Check the below link for configuration:

https://www.baeldung.com/linux/schedule-script-execution

CodePudding user response:

If you only want to start the script if not between 2am and 3am (but an allready started script does not need to be stopped) this could be easily checked with an additional if-statement:

#!/bin/bash
while true; do 
  if [[ 2 -le $(date ' %H') && $(date ' %H') -le 3 ]]; then 
    sleep 60
  else
    php /var/www/html/folder1/scripts/processtask.php /var/www/html/folder1/app
    sleep 8
  fi
done
  •  Tags:  
  • Related