/
Batch Script Contains DOS Line Breaks

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 in our Linux Environment, 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.




Related content

Script Fails or Misbehaves When Submitting From One Cluster to Another
Script Fails or Misbehaves When Submitting From One Cluster to Another
More like this
Connection Closed By Remote Host
Connection Closed By Remote Host
Read with this
slurmstepd: error: execve(): executable : No Such File or Directory
slurmstepd: error: execve(): executable : No Such File or Directory
More like this
QOSMaxJobs Appearing for Pending Slurm Jobs
QOSMaxJobs Appearing for Pending Slurm Jobs
Read with this
module: command not found
module: command not found
More like this
Slurm Job Cancelled Due to Time Limit
Slurm Job Cancelled Due to Time Limit
Read with this