Search code examples
mysqlperlsyntaxcronrackspace-cloud

Script for a for moving a large database in Rackspace - Perl


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!


Solution

  • 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.