To get the output in a file, add >> output_file
to the command (here echo "it worked"
)inside the sbatch
script. Because, the command inside sbatch is executed on all nodes and writes it into stdout
. The sbatch
command just submit the job to the controller and only returns the output to the login node about the job submission.
#!/bin/bash
#SBATCH -N 1
#SBATCH -n 1
echo "It worked!" >> output_file
Why so?
sbatch
exits immediately after the script is successfully transferred to the Slurm controller and assigned a Slurm job ID. So, it is the only output of the command sbatch some_script.sh >> somefile.txt
. Thats why you will only get information about submitting jobs to the controller.
The batch script is not necessarily granted resources immediately, it may sit in the queue of pending jobs for some time before its required resources become available.
As in the answer by damienfrancois, the file is created when job is started. By default both standard output and standard error are directed to a file of the name "slurm-%j.out
", where the "%j
" is replaced with the job allocation number. The file will be generated on the first node of the job allocation. Other than the batch script itself, Slurm does no movement of user files.
When the job allocation is finally granted for the batch script, Slurm runs a single copy of the batch script on the first node in the set of allocated nodes.