Ruby on rails 将ruby on rails应用程序部署到AWS时出现奇怪的问题

Ruby on rails 将ruby on rails应用程序部署到AWS时出现奇怪的问题,ruby-on-rails,ruby,amazon-web-services,Ruby On Rails,Ruby,Amazon Web Services,我目前正尝试在AWS服务器上使用where设置cronjobs,但当我尝试运行script/rails文件时,我收到以下消息: -bash: script/rails: /usr/bin/ruby^M: bad interpreter: No such file or directory 而脚本/rails文件包含以下内容: #!/usr/bin/ruby # This command will automatically be run when you run "rails" with Ra

我目前正尝试在AWS服务器上使用where设置cronjobs,但当我尝试运行script/rails文件时,我收到以下消息:

-bash: script/rails: /usr/bin/ruby^M: bad interpreter: No such file or directory
而脚本/rails文件包含以下内容:

#!/usr/bin/ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application',  __FILE__)
require File.expand_path('../../config/boot',  __FILE__)
require 'rails/commands'
在我看来,不管出于什么原因,在第一行附加了一个额外的^M。还请注意,我正在windows上开发并部署到AWS ubuntu服务器。有人知道我如何解决这个问题吗?我试着给尽可能多的指导,但这是一个奇怪的问题。注意:我只是尝试通过ssh在ubuntu机器上创建文件,但当我编写脚本/rails时,它会尝试执行rails本身。 谢谢
Cody

可能是一个行尾问题,windows代表的新行与linux不同,因此当您上载文件时,它不会被正确解释。如果您在服务器上使用vim或vi打开文件,您应该会看到行末尾的^M(Control-M)字符


如果您是通过ftp上传的,您可以尝试在binmode模式下上传该文件,这可能会解决问题。否则,您可以使用vi打开文件并删除服务器上有问题的字符:。希望有帮助。

我假设您是在windows计算机上创建此脚本的。Windows使用
\r\n
作为回车符(新行字符),而linux只使用
\n
。这意味着,当您将在windows上编写的脚本传输到linux机器上时,多余的
\r
字符有时会显示为
^M
。有几个修复程序,其中最简单的一个是通过
sed
运行文件并替换以下字符:

sed -i 's/\r$//' filename
例如:

➜  echo -ne "hello\r\nworld" > example.txt
➜  cat example.txt | od -c
0000000   h   e   l   l   o  \r  \n   w   o   r   l   d
0000014
➜  sed -i 's/\r$//' example.txt
➜  cat example.txt | od -c
0000000   h   e   l   l   o  \n   w   o   r   l   d

其他选项。

此外,每当我运行得到路径/usr/bin/rubyglad帮助的程序时,您可以通过单击左侧的勾号来接受正确的答案。