LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-03-2013, 03:00 PM   #1
Weekend_warrior1999
LQ Newbie
 
Registered: Feb 2013
Posts: 11

Rep: Reputation: Disabled
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

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
 
Old 02-05-2013, 01:06 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,537

Rep: Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907Reputation: 1907
How is this any different to your current question seen here?
 
2 members found this post helpful.
Old 02-05-2013, 06:39 PM   #3
Weekend_warrior1999
LQ Newbie
 
Registered: Feb 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does this work from the bash command line and then fails in a bash script? Rupadhya Linux - Newbie 5 09-26-2012 12:05 AM
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 02:40 AM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM


All times are GMT -5. The time now is 07:34 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration