Uncategorised
Automating Magmi with cron and systemd
Scheduled imports, logging, Slack notifications, protection against double runs.
Published 2026-09-02 • Category: DevOps • Reading time: 7 min
Step 1: Magmi profile
Build the profile in the Magmi UI, test it, save it. We’ll call it stock_sync.
Step 2: CLI command
php /var/www/magento/magmi/magmi/cli/magmi.cli.php \
-profile=stock_sync -mode=update \
-CSV:filename=/import/stock.csv \
-silent=1
-silent=1 suppresses UI-style output. Logs go to /var/log/magmi.log.
Step 3: Cron
# hourly sync
0 * * * * flock -n /tmp/magmi.lock -c "php /path/to/magmi.cli.php -profile=stock_sync -silent=1 >> /var/log/magmi.log 2>&1"
flock guarantees that two cron runs of the same profile won’t overlap.
Step 4: systemd timer (production-ready)
If cron isn’t your style — a systemd timer gives you more control and better logs:
# /etc/systemd/system/magmi-stock.service
[Unit]
Description=Magmi Stock Sync
[Service]
Type=oneshot
User=www-data
ExecStart=/usr/bin/php /path/to/magmi.cli.php -profile=stock_sync
# /etc/systemd/system/magmi-stock.timer
[Unit]
Description=Hourly Magmi Stock Sync
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
Step 5: Slack notifications
#!/bin/bash
php /path/magmi.cli.php -profile=stock_sync > /tmp/magmi.out 2>&1
if [ $? -ne 0 ]; then
curl -X POST -H "Content-type: application/json" \
--data "{\"text\":\"⚠ Magmi import failed. See /tmp/magmi.out\"}" \
"$SLACK_WEBHOOK_URL"
fi
Leave a Reply