”/ bin / bash ^ M:坏翻译:没有这样的文件或目录”错误时执行一个bash脚本从一个cron作业

时间:2021-07-06 15:29:24

Restore_DB.sh :-

Restore_DB。承宪:-

#!/bin/bash
mysql -u user -ppassword DB_name < /home/A/B/SQL_File.sql

I used the above code to restore a MySQL database from a cron job but I'm getting the bellow error

我使用上面的代码从cron作业中恢复MySQL数据库,但是我得到了bellow错误。

/usr/local/cpanel/bin/jailshell: /home/A/B/Restore_DB.sh: /bin/bash^M: bad interpreter: No such file or directory

This is the cron job command I used:-

这是我使用的cron作业命令:-。

/home/A/B/Restore_DB.sh

4 个解决方案

#1


2  

his looks like a problem with different line end encodings on unixoid and MS-Windows like systems.

他的看起来像一个问题,不同的线端编码在unixoid和MS-Windows类似系统。

Use the line ending \n which is native to unixoid systems, not the MS-Windows style. That one holds an extra character which is typically displayed like what you see in the error message (^M).

使用基于unixoid系统的行结束\n,而不是MS-Windows风格。一个拥有一个额外的字符通常显示喜欢你所看到的错误消息(^)。

You can take a closer look at the line in question by using a hexeditor. This allows you to see exactly what non-printable characters are used inside a string.

您可以通过使用一个hexeditor来仔细查看这一行。这使您能够准确地看到字符串中使用了哪些不可打印字符。

#2


5  

Try if dos2unix can fix your file:

如果dos2unix可以修复您的文件:

$ dos2unix /home/A/B/Restore_DB.sh

If dos2unix does not exist yet, you can install it with your distribution's package manager.

如果dos2unix还不存在,您可以将其安装到您的发行版的包管理器中。

The problem is the newline encoding, Windows/DOS encodes newlines differently than Unix.

问题在于换行编码、Windows/DOS对新行代码的编码方式与Unix不同。

  • Unix newline sequence: \n (only line feed character)
  • Unix换行序列:\n(仅行提要字符)
  • Windows newline sequence: \r\n (2 characters, carriage return and line feed)
  • Windows换行程序:\r\n(2个字符,回车和换行)

See https://en.wikipedia.org/wiki/Newline#Representations

见https://en.wikipedia.org/wiki/Newline #表示

#3


2  

I just ran into this on OS X and noticed dos2unix is available as a brew formula:

我在OS X上遇到这个问题,注意到dos2unix是一个brew公式:

brew install dos2unix

#4


0  

yum install dos2unix

yum安装dos2unix

works like a charm !!!!

工作就像一种魅力!!!!

#1


2  

his looks like a problem with different line end encodings on unixoid and MS-Windows like systems.

他的看起来像一个问题,不同的线端编码在unixoid和MS-Windows类似系统。

Use the line ending \n which is native to unixoid systems, not the MS-Windows style. That one holds an extra character which is typically displayed like what you see in the error message (^M).

使用基于unixoid系统的行结束\n,而不是MS-Windows风格。一个拥有一个额外的字符通常显示喜欢你所看到的错误消息(^)。

You can take a closer look at the line in question by using a hexeditor. This allows you to see exactly what non-printable characters are used inside a string.

您可以通过使用一个hexeditor来仔细查看这一行。这使您能够准确地看到字符串中使用了哪些不可打印字符。

#2


5  

Try if dos2unix can fix your file:

如果dos2unix可以修复您的文件:

$ dos2unix /home/A/B/Restore_DB.sh

If dos2unix does not exist yet, you can install it with your distribution's package manager.

如果dos2unix还不存在,您可以将其安装到您的发行版的包管理器中。

The problem is the newline encoding, Windows/DOS encodes newlines differently than Unix.

问题在于换行编码、Windows/DOS对新行代码的编码方式与Unix不同。

  • Unix newline sequence: \n (only line feed character)
  • Unix换行序列:\n(仅行提要字符)
  • Windows newline sequence: \r\n (2 characters, carriage return and line feed)
  • Windows换行程序:\r\n(2个字符,回车和换行)

See https://en.wikipedia.org/wiki/Newline#Representations

见https://en.wikipedia.org/wiki/Newline #表示

#3


2  

I just ran into this on OS X and noticed dos2unix is available as a brew formula:

我在OS X上遇到这个问题,注意到dos2unix是一个brew公式:

brew install dos2unix

#4


0  

yum install dos2unix

yum安装dos2unix

works like a charm !!!!

工作就像一种魅力!!!!