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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42806630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:53:18  来源:igfitidea点击:

Crontab bash script: no such file or directory

bashshellcrontab

提问by ph3nx

A bash script is executed with crontab. For each run the following error is delivered as email:

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

/opt/Informatica/pcdev/scripts/startworkflow_trg.sh: line 1: #!/bin/bash: No such file or directory

Content in the crontab is as follows:

crontab中的内容如下:

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

The script works as it should, but the error emails are piling up in the inbox. How can this error be solved?

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

采纳答案by ph3nx

To find the line in the script where the error occurs different parts of the script were commented out. The problem occured even when there was only the first line left, containing: #!/bin/bash

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

The problem was solved by creating a new script and writing the first line from above manually and pasting the remaining content of the old script. We think there were characters in the first line of the script that were not visible in our editor.

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

回答by K Donahue

The issue occurs when copying and pasting lines between Windows and Linux when doing a crontab -e.

在执行crontab -e.

The Windows LFchar x'0d'gets inserted and causes issues. The solution is to remove all lines and type them back in. You can spot the issue by doing a crontab -l | od -xand looking for the 0dcharacters.

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