0

I am using sbatch to run scripts, and I want the output text to be written in a file from a certain point, i.e. I want to echo some text so the user can see, but after a certain command I want all output to be written in a file. Is there a way to do it? If not, how can I disable entirely the output logging?

EDIT: Example:

#!/bin/bash
#SBATCH --partition analysis
#SBATCH --nodes 1
#SBATCH --ntasks-per-node 1
#SBATCH --exclusive
#SBATCH --time 14-0
#SBATCH -c1
#SBATCH --mem=400M
#SBATCH --job-name jupyter

module load jupyter

## get tunneling info
XDG_RUNTIME_DIR=""

ipnip=$(hostname -i)


echo "
    Copy/Paste this in your local terminal to ssh tunnel with remote
    -----------------------------------------------------------------
    ssh -N -L 7905:$ipnip:7905 USER@HOST
    -----------------------------------------------------------------
    "
##UP UNTIL HERE ECHO TO TERMINAL

##FROM NOW ON, ECHO TO A FILE

## start an ipcluster instance and launch jupyter server
jupyter-notebook --no-browser --port=7905 --ip=$ipnip
Joshhh
  • 425
  • 1
  • 4
  • 18

1 Answers1

0

As per my comment above, it's not possible to write to terminal with an sbatch submitted job.

You can do that with srun in the following way:

#!/bin/bash
srun --partition analysis --nodes 1 --ntasks-per-node 1 --exclusive --time 14-0 -c1 --mem=400M --job-name jupyter wrapper.sh

wrapper.sh:

#!/bin/bash
module load jupyter

## get tunneling info
XDG_RUNTIME_DIR=""

ipnip=$(hostname -i)


echo "
    Copy/Paste this in your local terminal to ssh tunnel with remote
    -----------------------------------------------------------------
    ssh -N -L 7905:$ipnip:7905 USER@HOST
    -----------------------------------------------------------------
    "
##UP UNTIL HERE ECHO TO TERMINAL

##FROM NOW ON, ECHO TO A FILE
exec > $SLURM_JOBID.out 2>&1
## start an ipcluster instance and launch jupyter server
jupyter-notebook --no-browser --port=7905 --ip=$ipnip
Carles Fenoy
  • 4,740
  • 1
  • 26
  • 27