Skip to content

Instantly share code, notes, and snippets.

@mokanfar
Last active February 17, 2016 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mokanfar/3cf24bc51e4e84e7ff83 to your computer and use it in GitHub Desktop.
Save mokanfar/3cf24bc51e4e84e7ff83 to your computer and use it in GitHub Desktop.
Magento Magmi Import Cron Bash Script
#!/bin/bash
####################### BEGIN CONFIG #######################
csv_sheet_url='http://dev.com/example.csv'
csv_sheet_path='/home/dev/magmi.csv'
tmp_file_path='/home/dev/tmp_magmi.csv'
magmi_cli_path='/home/dev/magmi/cli/magmi.cli.php'
log_file='/home/dev/log.txt'
profile='Default'
######################## END CONFIG ########################
#downloading csv sheet
wget "$csv_sheet_url" -O "$tmp_file_path" >/dev/null 2>&1
#calculating md5sum
md5sum_download=$(md5sum "$tmp_file_path" | awk '{print $1}')
md5sum_existing=$(md5sum "$csv_sheet_path" | awk '{print $1}')
#comparing md5sum
if [ "$md5sum_download" != "$md5sum_existing" ]
then
echo "`date -u` -- found new csv sheet"> "$log_file"
#removing old csv sheet
rm -f "$csv_sheet_path"
#replacing new csv sheet
mv "$tmp_file_path" "$csv_sheet_path"
#running magmi.cli.php
php "$magmi_cli_path" -CSV:filename="$csv_sheet_path"
else
echo "`date -u` -- no new csv sheet found " > "$log_file"
#removing downloaded file
rm -f "$tmp_file_path"
fi
exit 0

#Cron Bash Script for Magento Nightly Updates Using Magmi CLI

This is meant for cron jobs that updates magento attributes via remote csv through magmi command line option. The script Downloads the csv, performs md5 checksum on the remote csv vs the one you have on your local to see if they differ, if they do, run the update using new csv through the magmi command line script (magmi.cli.php). If they are the same md5sum, exit the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment