Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I moved my system from ubuntu 9 to debian 5 and the cron each time that try to execute a script throws...

-bash: ./somescript.sh: /bin/sh^M: bad interpreter: No such file or directory

all my scripts begin with

#!/bin/sh

any clue ? should I change the shell cron is running ? it is using another shell ?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

That ^M bit makes me think that your script uses CR-LF line endings. This usually happens when you edit a file using a Windows text editor.

To fix it, install the tofrodos package and convert the file:

sudo aptitude install tofrodos
fromdos -b /path/to/script.sh
share|improve this answer
    
great, I'm using this, it worked perfectly. I used a windows machine as backup before the migration, that is why. Thanks –  Rodrigo Asensio Jun 30 '10 at 11:57

You have carriage returns in your document (Probably edited with a Windows program). You need to run:

cat somecript.sh | tr -d '\r' > somescript2.sh

Make sure that you use a new file name like I did in my example (somescript2.sh). You can read this blog post for the full story.

share|improve this answer
1  
Here, have a UUOC award. :-p –  ThatGraemeGuy Jun 30 '10 at 11:51
    
Well since tr doesn't take filename arguments I figure that is a little clearer than tr -d '\r' < input > output –  Kyle Brandt Jun 30 '10 at 12:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.