5

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

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

Content in the crontab is as follows:

# 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?

6
  • Do you receive the same error message when running the script manually? Commented Mar 15, 2017 at 10:21
  • 1
    what is the output of echo $HOME ? Commented Mar 15, 2017 at 10:24
  • 2
    Change ~ to $HOME and remove the unnecessary parentheses and replace the semi-colon with &&. Commented Mar 15, 2017 at 10:25
  • How do you call the script out of the cron context ? Commented Mar 15, 2017 at 13:09
  • @ZumodeVidrio at first I thought it is a problem with the crontab configuration, but now I noticed that the error also appears while running the script manually. Commented Mar 16, 2017 at 10:41

2 Answers 2

9

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

The Windows LF char 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 -x and looking for the 0d characters.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.