MongoDB script from Windows upload to Linux cannot perform __linux

Source: Internet
Author: User
Tags mongodb
One: Problem description

These several times perform MongoDB initialization scripts and discover a problem:

When you upload a script from Windows to Linux, the error occurs when you execute it.

Such as:

Mongo-u root-p mongo123 Admin--port 8000 < initdata-bmis.sql > Initdata-bmis.log

There are many errors in the Initdata-bmis.log file:

Syntaxerror:unexpected token illegal But the direct copy paste script content executes on the command line without an error. or copy and paste the content into the new file under Linux, and execute without error.

And the script determines that there are no syntax errors.


Two: The cause of the error

formatting problems, Windows and Linux/unix are different for line breaks and blank lines.


III: Solutions

Method One:

While editing in notepad++ is encoded in UTF8 format, there is a place that requires transcoding, and windows and Linux/unix line breaks and blank lines are different, so the script edited under Windows can't run on Linux, After the notepad++ can be used in the transfer code.

Method Two:

Install Dos2unix on Linux and turn code

Yum Install-y Dos2unix

Dos2unix Initdata-bmis.sql

Do it again without an error:

Mongo-u root-p mongo123 Admin--port 8000 < initdata-bmis.sql > Initdata-bmis.log



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.