I am trying to make a bash script that works with OSCommerce to import a CSV file into the products data base using cURL. This is what I have so far, but it all works other then the actual Form post using cURL. what I need help with is that when I run it does always actually post the data. it seems that if it hadn't been ran in a long time "hours" it would fail, but if you comment out the "rm" comments at the end of the script, and run it twice just minutes apart it works.... I'm at a loss as to what I'm missing... Maybe someone can give me a hand... Thanx
Quote:
#!/bin/bash
#Login To Obtain Session Cookie
dbuser="dbadmin"
dbpass="dbpassword"
dbserver="1234124.hostedresource.com"
db="yourdb"
table="products"
csvfile="/home/content/72/10252872/html/catalog/temp/products_all_`date +%d%b%Y`.txt"
user="administrator" #OSCommerce User to use for update operation
pass="reallygoodpasswordlol" #OSCommerce password to use for update operation
admin_URL="http://yourURL.com/catalog/admin" #URL to admin directory, NOTE: No Traiing Slash in URL
admin_creds_URL="http://$user:$pass@$admin_URL"
store_URL="http://your-URL.com/catalog" #URL of store
local_dir="/home/content/72/10252872/html/catalog" #Local directory where files are stored, NOTE: No trailing slash
csv_filename="products_all_" #Prefix to attach to CSV filename
image_DL_URL="image-DL-url.com/image.tar.gz"
csv_DL_URL="CSV-DL-URL.com/CSV.txt"
supplier_name="supplier_name"
csv_ext="txt"
arch_ext="tar.gz"
catagory_image="catagory.jpg"
clear
echo "Login and store session information for phase2 of import process"
curl -v --cookie cookies.txt \
--cookie-jar cookies.txt \
-D Headers.txt \
--user-agent Mozilla/4.0 \
-u $user:$pass \
--data "username=$user&password=$pass" \
$admin_URL/login.php?action=process
echo "Clear Temp Data matching: $local_dir/temp/$csv_filename*"
rm $local_dir/temp/$csv_filename*
echo .
echo "H & D Supplier Update"
echo "Download Supplier Catalog Images to: $local_dir/temp/$csv_filename`date +%d%b%Y`.$arch_ext"
wget -O $local_dir/temp/$csv_filename`date +%d%b%Y`.$arch_ext "$image_DL_URL"
echo .
echo "Delete old Supplier Catalog Images in: $local_dir/images/images/*"
rm $local_dir/images/images/*
echo .
echo "Unarchive Supplier Catalog Images to: $local_dir/images/images"
tar -xzf $local_dir/temp/$csv_filename`date +%d%b%Y`.$arch_ext -C $local_dir/images/images
echo .
echo "Download Supplier Product Catalog: $local_dir/temp/$csv_filename`date +%d%b%Y`.$csv_ext"
wget -O $local_dir/temp/$csv_filename`date +%d%b%Y`.$csv_ext "$csv_DL_URL"
echo .
echo "Catalog file renamed for processing:$csv_filename`date +%d%b%Y`.$csv_ext to $supplier_name.$csv_ext in $local_dir/temp/"
mv $local_dir/temp/$csv_filename`date +%d%b%Y`.$csv_ext $local_dir/temp/$supplier_name.$csv_ext
echo "Operation Complete, ready for second phase of import procedure"
sed '1,4 d' cookies.txt > saved-cookies
while IFS=$'\t' read -r -a myArray
do
echo ${myArray[0]}
echo ${myArray[1]}
echo ${myArray[2]}
echo ${myArray[3]}
echo ${myArray[4]}
echo ${myArray[5]}
echo ${myArray[6]}
echo ${myArray[7]}
# Open Easy Populate and post variable to import newly downloaded CSV file
curl -v -b cookies.txt \
--user-agent Mozilla/4.0 \
-u admin:steelbird89 \
-H Headers.txt \
--referer "$admin_URL/login.php?${myArray[5]}=${myArray[6]}" \
-F ${myArray[5]}=${myArray[6]} -F localfile=$supplier_name.$csv_ext -F imput_mode=normal -F buttoninsert=Insert%20into%20db \
$admin_URL/easypopulate.php
# Import Should be complete
echo "Import of $supplier_name products complete"
done < saved-cookies
echo "Update DB tables to disable products that have ZERO stock quantity"
mysql -u$dbuser -p$dbpass -h$dbserver -D$db <<< 'UPDATE `products` SET `products_status`="0" WHERE `products_quantity`="0";'
echo .
echo "Update DB tables to set a generic category image for newly added categories"
mysql -u$dbuser -p$dbpass -h$dbserver -D$db <<< 'UPDATE `categories` SET `categories_image`="$catagory_image" WHERE `categories_image`="";'
rm cookies.txt
rm Headers.txt
rm saved-cookies
|