这是我的 bash 脚本
#!/bin/bash
timestamp() {
date +"%T"
}
pushd 'httpdocs/DIR1/DIR2';
file="Lock3.key"
if [ -f "$file" ]
then
echo "$file found, Session is already in progress" $(date)
else
echo "$file was not found, Its safe to start the script" $(date)
echo "Running Ebay Stock Only Script" $(date)
#Its possible to double check if the script is running by checking memory.
#ps aux | grep "php Cron-Run.php" (Not safe)
php Cron-Run.php > Output.log
echo "Finished Running Script, Lock file is deleted by PHP, Now exiting" $(date)
fi
exit
这是从 cron 作业运行的,并且有效。但我想要的是最后一个echo
仅在 PHP 进程完成时运行(它将运行一个小时),并且当电子邮件通过时,很高兴看到最后一个的输出echo
以及相关时间。
目前,echo
PHP 脚本调用后两秒运行。
答案1
我可以使用等待函数暂停/等待该过程完成。
工作部分的示例:
#!/bin/bash
timestamp() {
date +"%T"
}
pushd 'httpdocs/DIR1/DIR2';
file="Lock3.key"
if [ -f "$file" ]
then
echo "$file found, Session is already in progress" $(date)
else
echo "$file was not found, Its safe to start the script" $(date)
echo "Running Ebay Stock Only Script" $(date)
#Its possible to double check if the script is running by checking memory.
#ps aux | grep "php Cron-Run.php" (Not safe)
php Cron-Run.php > Output.log
wait
echo "Finished Running Script, Lock file is deleted by PHP, Now exiting" $(date)
fi
exit