Batch Script Contains DOS Line Breaks

Problem

When submitting a job with sbatch, it produces an error:

Listing 1: DOS line breaks error message
sbatch: error: Batch script contains DOS line breaks (\r\n)
sbatch: error: instead of expected UNIX line breaks (\n)

This is due to a text editor encoding your Slurm batch script using DOS-style line breaks. This often occurs when creating or editing a script on a Windows system. DOS line breaks consist of two separate characters: a carriage return character (often notated as \r) and a new line feed character (as \n) which can be seen in the error message. This style of line break is incompatible with Slurm and you will need to modify your script before it will run with sbatch.

Solution

Slurm expects UNIX-style line breaks which only have a single line feed character (\n) and no carriage return characters - deleting the carriage returns will resolve the issue. The most immediate remedy is using the in-built dos2unix utility, available on the login nodes. The default behaviour of the utility is to overwrite the existing file as it makes the necessary changes. Example use:

Terminal 1: Convert to Unix style format
$ dos2unix my_sbatch_script.sh


To prevent the issue from reoccurring, a different approach to editing your scripts is required. We recommend using the text editors available on the clusters, which use UNIX line breaks by default; or using Notepad++ (external link) if you prefer to script on Windows, which has features to save files using UNIX line breaks if required.

Filter by label

There are no items with the selected labels at this time.