Hongmu Notes
Home Summary of pitfalls PHP can be executed periodically using the PaTa server or run from the command line.
Summary of pitfalls

PHP can be executed periodically using the PaTa server or run from the command line.

PHP can be executed periodically using the PaTa server or run from the command line.

This is a Bash script designed to automatically execute PHP migration scripts within the Pagoda Panel scheduled tasks. Its primary function is to ensure that the migration script is run only once per instance, prevent duplicate executions, and log both the execution process and the results to a log file.

#!/bin/bash
# 自动迁移脚本 - 配合宝塔计划任务使用

# ===== 配置区域 =====
PHP_PATH="/www/server/php/83/bin/php"          # PHP 可执行文件路径(根据实际版本修改)
SCRIPT_PATH="/www/wwwroot/1.php"
LOG_FILE="/www/server/cron/4041704b46a517bb6a6a28b638721a08.log"
PID_FILE="/www/wwwroot/migrate.pid"
# ====================

# 检查是否已在运行
if [ -f "$PID_FILE" ]; then
    OLD_PID=$(cat "$PID_FILE")
    if ps -p "$OLD_PID" > /dev/null 2>&1; then
        echo "$(date '+%Y-%m-%d %H:%M:%S') 迁移脚本已在运行 (PID: $OLD_PID),跳过本次执行。" >> "$LOG_FILE"
        exit 0
    else
        rm -f "$PID_FILE"
    fi
fi

# 记录当前进程 PID
echo $$ > "$PID_FILE"

# 执行迁移脚本,输出重定向到日志文件
echo "$(date '+%Y-%m-%d %H:%M:%S') 开始执行迁移脚本..." >> "$LOG_FILE"
$PHP_PATH $SCRIPT_PATH >> "$LOG_FILE" 2>&1

# 执行完毕,清理 PID 文件
rm -f "$PID_FILE"

echo "$(date '+%Y-%m-%d %H:%M:%S') 迁移脚本执行完毕。" >> "$LOG_FILE"

This script is typically used in the "Scheduled Tasks" section of the PaTa Panel to periodically (e.g., every minute or every hour) execute a PHP migration task. It prevents overlapping task executions by using a PID file (so that the next task does not run until the previous one has been completed) and logs all output to a specified log file, facilitating troubleshooting.

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 200

Recommended reading

Dental Cosmetic Surgery Company Website Template 1040

Dental Cosmetic Surgery Company Website Template 1040 Practical Collection Yiyou template

This EyouCMS template is ideal for dental aesthetics and healthcare businesses. Its professional and clean design effectively showcases dental aesthetic treatments, medical teams, diagnostic and treatment equipment, as well as successful case studies. It helps dental clinics attract patients online and enhance their brand professionalism. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 39
(Adaptive mobile version) Responsive e-device website PBootCMS template – includes download functionality – 1035

(Adaptive mobile version) Responsive e-device website PBootCMS template – includes download functionality – 1035 Practical Collection pbootcms Template

A responsive PbootCMS website template suitable for both PC and WAP devices, featuring a download function. The modern, tech-oriented design is ideal for electronics companies to showcase their products and download technical documentation. This template helps electronics enterprises present their brands online and attract customers. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 46
Responsive premium watch and luggage website template – 0442

Responsive premium watch and luggage website template – 0442 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the premium watch and luggage industry, featuring a high-end, fashionable design style perfect for showcasing watch products, luggage collections, brand stories, and customisation services. It helps luxury brands showcase their products online and attract high-net-worth customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 46
(Adaptive Mobile Version) Responsive industrial steel machinery website using PBootCMS template – Download HTML5 industrial equipment website source code: 0472

(Adaptive Mobile Version) Responsive industrial steel machinery website using PBootCMS template – Download HTML5 industrial equipment website source code: 0472 Practical Collection pbootcms Template

An adaptive mobile-friendly LED lighting and green lighting PbootCMS website template. Featuring a modern, energy-efficient design, this template is ideal for LED lighting manufacturers and lighting engineering companies to showcase their products. It helps lighting enterprises present their brands online and attract both engineering and international trade clients. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 39
Responsive Visual Design Beauty & Hairdressing Website Template 1041

Responsive Visual Design Beauty & Hairdressing Website Template 1041 Practical Collection Yiyou template

An eyouCMS responsive website template designed for the image design, beauty, and hairdressing industries. Its stylish and sophisticated design enables effective presentation of image design projects, beauty and hairdressing services, trendy styling concepts, and brand stories – helping beauty and hairdressing businesses attract customers online. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for YIYOU CMS | YIYOU CMS...
👁 58