我把我的系统从Ubuntu 9移动到debian 5和每次试图执行脚本的Cron抛出…
-bash: ./somescript.sh: /bin/sh^M: bad interpreter: No such file or directory
我所有的脚本都以
#!/bin/sh
任何线索? 我应该改变shell的cron运行? 它正在使用另一个shell?
^M位让我觉得你的脚本使用CR-LF行尾 。 这通常发生在使用Windows文本编辑器编辑文件时。
要修复它,请安装tofrodos包并转换文件:
sudo aptitude install tofrodos fromdos -b /path/to/script.sh
您的文档中有回车(可能是用Windows程序编辑)。 你需要运行:
cat somecript.sh | tr -d '\r' > somescript2.sh
确保你像我在我的例子( somescript2.sh )中使用一个新的文件名。 你可以阅读这篇博客文章的完整故事。