Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab bash script: no such file or directory

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?

like image 401
ph3nx Avatar asked Mar 15 '17 10:03

ph3nx


2 Answers

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.

like image 175
K Donahue Avatar answered Oct 24 '22 09:10

K Donahue


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.

like image 44
ph3nx Avatar answered Oct 24 '22 09:10

ph3nx