Reputation: 3
I have no experience in Perl. We are trying to move our 250MB database into MySQL with a Perl script that is scheduled as a Cron Job The Rackspace cloud has recommend this script:
#!/bin/sh mysql -h DB_HOST -u DB_USER -p'DB_PASSWORD' DB_NAME < /path/to/file/db_import.sql
I have filled in the variables as so (user and pass have changed for this post):
!/bin/sh mysql -h mysql51-032.wc1:3306 -u 806637_Admin -p '*******' 806637_Vs_Hl < /mnt/stor09-wc1-ord1/762283/806637/www.vs-hl.com/Vs-hlDB/Vs-DB.sql
Doing some research I found that the '#' starts a comment in Perl so I removed it and this is what I received as an error report:
Bareword found where operator expected at main.pl line 1, near "/bin/sh" (Missing operator before h?)
Bareword found where operator expected at main.pl line 1, near "806637_VMHAdmin" (Missing operator before VMHAdmin?)
Number found where operator expected at main.pl line 1, near "'Admin1234' 806637_" (Missing operator before 806637_?)
Bareword found where operator expected at main.pl line 1, near "806637_Vets_Hall" (Missing operator before Vets_Hall?)
syntax error at main.pl line 1, near "/bin/sh mysql "
Execution of main.pl aborted due to compilation errors.
My question is what am I doing wrong syntax wise? Thanks for reading!
Upvotes: 0
Views: 111
Reputation: 558
A Perl "script" and shell script are not the same things. So when dealing with programmers, I call it a "Perl program" since Perl is a fully functional programming language. This is a shell script which uses 2 separate lines:
#!/bin/sh
mysql ...
That has nothing to do with Perl. If you want to execute a command in Perl you can do this inside a Perl program. I'll call it doit.pl:
# Note I'm using backticks, and any error msgs are in $msg.
$msg=`mysql -h DB_HOST -u DB_USER -p'DB_PASSWORD' DB_NAME < /path/to/file/db_import.sql`;
print "Messages are: $msg\n";
And you don't need Perl if nothing in the command line changes. You could use Perl if you are looping through and copying many database names though.
Upvotes: 0
Reputation: 4445
That's not a Perl script, that's a Bourne Shell script. Just move it onto two separate lines.
#!/bin/sh
mysql ...
Note that the #!
has to be the very first two characters of the file. No blank lines may proceed it.
Upvotes: 1