如何通过shell脚本运行symfony命令

jk9hmnmh  于 2023-03-09  发布在  Shell
关注(0)|答案(1)|浏览(179)

我有一个symfony命令,我想从shell脚本中使用它。
例如:symfony我的命令。
我在项目文件夹中有一个脚本shell,我将symfony命令作为参数传递给它。
sh脚本:

time=$1
php_script_path=$2
log_file="script.log"

# Infinite loop
while true; do
    # Loop over the PHP script until the timeout is reached
    while timeout $time php $php_script_path; do
        # This code will only execute if the PHP script exits successfully within the timeout period
        echo "$(date): PHP script executed successfully" >> $log_file
    done

    # This code will only execute if the PHP script did not exit successfully within the timeout period
    if [ $? -eq 124 ]; then
        echo "$(date): PHP script timed out" >> $log_file
    else
        echo "$(date): PHP script completed with an error" >> $log_file
    fi
done
s8vozzvw

s8vozzvw1#

您可以使用与cron命令相同的命令。请在下面的PHP脚本中设置项目路径。

time=$1
php_script_path="/var/www/project/bin/console app:your_command_name"
log_file="script.log"

# Infinite loop
while true; do
    # Loop over the PHP script until the timeout is reached
    while timeout $time php $php_script_path; do
        # This code will only execute if the PHP script exits successfully within the timeout period
        echo "$(date): PHP script executed successfully" >> $log_file
    done

    # This code will only execute if the PHP script did not exit successfully within the timeout period
    if [ $? -eq 124 ]; then
        echo "$(date): PHP script timed out" >> $log_file
    else
        echo "$(date): PHP script completed with an error" >> $log_file
    fi
done

相关问题