To attach (or reattach) to the output of a Slurm job that was started with sbatch, you typically use the sattach command. This allows you to connect to the job's standard input, output, and error streams, similar to how you would interact with a terminal session.
sattachFind Your Job ID
First, you need the job ID of the running Slurm job. You can find this using:
bashsqueue -u $USER
This will list your jobs along with their IDs.
Attach to the Job
Once you have the job ID, use:
bashsattach <job_id>
Replace <job_id> with the actual job ID.
For example:
bashsattach 12345
Detach from the Job
To detach, press Ctrl+C or use the escape sequence ~. (tilde followed by a dot) if you are using a terminal multiplexer like screen or tmux.
sattach only works if the job is currently running. If the job has finished, you cannot attach to it.sattach is most useful for interactive jobs or jobs that produce ongoing output.--pty or similar options, attaching may not work as expected.bash# Submit a job sbatch --pty my_script.sh # Find the job ID squeue -u $USER # Attach to the job sattach 12345