I have written the script below, but when I run it from the directory where it is (and also the files)
bash xmlimport-magento2.sh
I get this error message:
xmlimport-magento2.sh: line 7: syntax error near unexpected token $'do\r''
mlimport-magento2.sh: line 7: do
#!/bin/bash
if exists *.ZIP
then
# disable autoindexing
#php -f "$MAGEPATH"shell/indexer.php -- --mode-manual all
for file in `ls *.ZIP`
do
# Backup zip file
cp $file /backups
# Extract XML files
unzip -P web $file
# Delete zip file
rm -f $file
# rename xml files
# hier komt procedure die controleert of bestand xxx*basic.xml bestaat en zo ja dan wordt dit bestand hernoemt en daarna geexecuteerd
if [ -f "*basic.xml" ]
then
mv *_BASIC.XML BASIC.XML
php -f bin/magento import:job:run 1
fi
# rename xml files
# hier komt procedure die controleert of bestand xxx*prices.xml bestaat en zo ja dan wordt dit bestand hernoemt en daarna geexecuteerd
if [ -f "*prices.xml" ]
then
mv *_PRICES.XML PRICES.XML
php -f bin/magento import:job:run 4
php -f bin/magento import:job:run 2
fi
# rename xml files
# hier komt procedure die controleert of bestand xxx*stock.xml bestaat en zo ja dan wordt dit bestand hernoemt en daarna geexecuteerd
if [ -f "*stockinfo.xml" ]
then
mv *_STOCKINFO.XML STOCKSTOCK.XML
php -f bin/magento import:job:run 3
fi
done
# verplaats .XML files naar backup
cp -f $file ../backups
# Delete XML files
rm -f *.XML
fi
dos2unix
. You additionally usels
needlessly when you could just loop safer over the expansion of a file glob (for file in *.ZIP
). You have several other errors in your code which would make it fail to do what you want. I suggest rewriting it and testing each piece of code as you add it to the script. Also test what would happen with filenames containing spaces and globbing characters (touch '* name.ZIP'
; with current code, having a file with this name causes data loss due torm -f $file
). – Kusalananda May 31 '20 at 16:23for file in $(ls *.ZIP)
- useless and error prone use ofls
. – rexkogitans May 31 '20 at 17:53