So, you just uploaded a bash script to your server, its first line is #!/bin/bash
, and when you run it it stops with an error /bin/bash^M: bad interpreter: No such file or directory? You’ve probably created the file on Windows, using Windows line breaks, which apparently .sh scripts can’t handle properly. You’ll need to convert your line breaks to UNIX format. This can’t be done in Notepad (but hopefully you’re not using that), however it can be done in Notepad++, only it’s remarkably well hidden IMO. The menu item to look for is simply Edit → EOL conversion (EOL standing for end of line). Just pick the right format (it should indicate that you have Windows line breaks, just switch to UNIX line breaks).
Alternatively, you could also run dos2unix yourscript.sh
right on your server, although that’s something I found in some pretty old thread, and on Debian 7 at least this dos2unix thing doesn’t seem to be installed by default.
On a side note, I encountered this issue while copy/pasting this nice anti-w00tw00t scan script from spamcleaner.org.
Run following command in terminal
sed -i -e ‘s/\r$//’ scriptname.sh
Then try
./scriptname.sh
It should work.
Ref: https://stackoverflow.com/a/29747593