-   Programming (
-   -   Bash script help (

Weekend_warrior1999 02-03-2013 04:00 PM

Bash script help
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


#Login To Obtain Session Cookie
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="" #URL to admin directory, NOTE: No Traiing Slash in URL
store_URL="" #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

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" \

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
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 \
# 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

grail 02-05-2013 02:06 AM

How is this any different to your current question seen here?

Weekend_warrior1999 02-05-2013 07:39 PM

I made this post before making the required "welcome" post after registration, and didn't see that it had actually got posted and thought it had gotten ignored by the system. It wasn't until you actually made the above comment that I was made aware that it actually did.

All times are GMT -5. The time now is 03:12 PM.