0

I'm currently trying to setup cronjobs using whenever on an AWS server, but when i try to run the script/rails file I get the following message:

-bash: script/rails: /usr/bin/ruby^M: bad interpreter: No such file or directory

While the script/rails file contains the following:

#!/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'

It looks like to me for whatever reason an extra ^M is being appended to the first line. Also note that I'm developing on windows and deploying to an AWS ubuntu server. Does anyone have an idea of how I can fix this issue? I'm trying to give as much guidance as i can, but this is a weird problem. Note: I tried just creating the file on the ubuntu machine through ssh but it then tries to execute rails itself when i do script/rails. Thanks, Cody

2 Answers2

0

Could be a line ending issue where windows represents newlines differently than linux so when you uploaded the file it won't be interpreted properly. If you open the file with vim or vi on your server you should see the ^M (Control-M) character visible at the end of the line.

If you're uploading via ftp you can try uploading that file in binmode and that may resolve it. Otherwise you can open the file and remove the offending character on your server with vi: http://www.tech-recipes.com/rx/150/remove-m-characters-at-end-of-lines-in-vi/. Hope that helps.

ejlangev
  • 1
  • 1
0

I'm assuming you created this script on a windows computer. Windows uses \r\n for it's carriage return (new line character) where as linux simply uses \n. What this means is that when you take a script written on windows and transfer it onto a linux machine then the extra \r characters sometimes get displayed as ^M. There are a few fixes, one of the simplest is simply to run the file through sed and replace these characters:

sed -i 's/\r$//' filename

for instance:

➜  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

Additional options can be found here.

Community
  • 1
  • 1
Mike H-R
  • 7,726
  • 5
  • 43
  • 65