Printable Version of Topic

Click here to view this topic in its original format

Linuxhelp _ Technical Support _ Stuck with a cron job

Posted by: oracle765 Apr 1 2014, 02:53 AM

Hi professionals I hope I am posting in the right forum

I have a feed.sh file which I run in a cron job to try and import a tab delimited text file into MySQL database. Problem is I am new to Linux and I am fairly stuck so if someone could point my in the right direction that would be great

Here is the .sh file which I am trying to run, it seems to grab the text file ok and connect to the db but then produces errors

CODE
#Get price retailers list
/usr/bin/wget -O "/home/oracle765/public_html/feed/getprice.txt" 'http://www.getprice.com.au/affinityclick/ShopsList.aspx?Pass=1iob2kjd&ref=cc';


$dbh = mysql -u compareandchoose -p Comparechoose12 -h mysql.compareandchoose.com.au mydatabase # < /home/oracle765/public_html/feed/getprice.txt

$SQL = "LOAD DATA INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)";

$dbh->prepare($SQL);
$dbh->execute;
$dbh->finish;
$dbh->disconnect;


and here is the email error I receive

CODE
2014-04-01 00:29:02 (1.14 MB/s) - /home/oracle765/public_html/feed/getprice.txt saved [244130/244130]

/home/oracle765/public_html/scripts/feedimport.sh: line 14: =: command not found
/home/oracle765/public_html/scripts/feedimport.sh: line 16: =: command not found
/home/oracle765/public_html/scripts/feedimport.sh: line 18: syntax error near unexpected token `('
/home/oracle765/public_html/scripts/feedimport.sh: line 18: `$dbh->prepare($SQL);'

Posted by: michaelk Apr 1 2014, 08:28 AM

Is this your entire script? I assume it is bash.

I have been trying to determine what language or where the following came from:
$SQL = "LOAD DATA INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)";
$dbh->prepare($SQL);
$dbh->execute;
$dbh->finish;
$dbh->disconnect;

I do not use mysql but those statements will not run in bash.

You can run multiple mysql statements via something like this:
mysql dbnane<<EOFMYSQL
SELECT * from table;
EOFMYSQL

Posted by: oracle765 Apr 3 2014, 07:43 PM

Hi professionals I have an update

I now tried to run script.sh with the following command

#Get price retailers list
/usr/bin/wget -O "/home/oracle765/public_html/feed/getprice.txt" 'http://www.getprice.com.au/affinityclick/ShopsList.aspx?Pass=1iob2kjd&ref=cc';



mysql -u UNAME -p PASSWORD mysql.compareandchoose.com.au mydatabase -execute="LOAD DATA LOCAL INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)"

mysql -u UNAME -p PASSWORD -h localhost mydatabase -e "LOAD DATA INFILE '/home/oracle765/public_html/feed/getprice.txt' REPLACE INTO TABLE getpriceretailer FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' (id,name,url,logo,rank,products,List)"




BOTH OF THESE WONT WORK AND PRODUCE THE ERROR MESSAGE BELOW


mysql Ver 14.14 Distrib 5.5.32, for Linux (x86_64) using readline 5.1 Copyright © 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
--auto-rehash Enable automatic rehashing. One doesn't need to use
'rehash' to get table and field completion, but startup
and reconnecting may take a longer time. Disable with
--disable-auto-rehash.
(Defaults to on; use --skip-auto-rehash to disable.)
-A, --no-auto-rehash
and so on


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)