Crontab bash 脚本:没有这样的文件或目录

ph3*_*3nx 5 bash shell crontab

使用 crontab 执行 bash 脚本。对于每次运行,以下错误都会以电子邮件形式发送:

/opt/Informatica/pcdev/scripts/startworkflow_trg.sh: line 1: #!/bin/bash: No such file or directory
Run Code Online (Sandbox Code Playgroud)

crontab中的内容如下:

# Check queue and start corresponding processes in test
* * * * * (. ~/.bash_profile; $HOME/scripts/startworkflow_trg.sh tst)
Run Code Online (Sandbox Code Playgroud)

该脚本正常工作,但错误电子邮件在收件箱中堆积如山。如何解决这个错误?

小智 5

在执行crontab -e.

WindowsLF字符x'0d'被插入并导致问题。解决方案是删除所有行并重新输入。您可以通过执行 acrontab -l | od -x并查找0d字符来发现问题。


ph3*_*3nx 1

为了找到脚本中发生错误的行,脚本的不同部分被注释掉。即使只剩下第一行,也会出现问题,其中包含: #!/bin/bash

通过创建一个新脚本并手动编写上面的第一行并粘贴旧脚本的剩余内容,解决了该问题。我们认为脚本第一行中的某些字符在我们的编辑器中不可见。