Due to me having to re-authenticate with Kerberos I need to run my long lived processes in tmux. I wrote a script that I thought would work but it didn't. The issue is that after I run the tmux session, instead of running the following commands inside of tmux it puts me into a tmux session and only once I detach does it run the rest of the commands -- but it runs them outside the tmux session while I want it to run inside of the tmux session.
This is my current attempt:
# - get a job id for this tmux session
export SLURM_JOBID=$(python -c "import random;print(random.randint(0, 1_000_000))")
echo SLURM_JOBID = $SLURM_JOBID
export OUT_FILE=$PWD/main.sh.o$SLURM_JOBID
export ERR_FILE=$PWD/main.sh.e$SLURM_JOBID
- CAREFUL, if a job is already running it could do damage to it, rm reauth process, qian doesn't do it so skip it
top -u brando9
pkill -9 reauth -u brando9
- start tmux,
https://unix.stackexchange.com/questions/724877/custom-kerberos-tmux-doesnt-let-me-name-my-sessions-help-forcing-it
tmux new -s $SLURM_JOBID
/afs/cs/software/bin/krbtmux new -s $SLURM_JOBID
cat /afs/cs/software/bin/krbtmux
- reauth
/afs/cs/software/bin/reauth
echo $SU_PASSWORD | /afs/cs/software/bin/reauth
echo 'Secret' | /afs/cs/software/bin/reauth
echo 'totally secret password' | kinit user@DOMAIN.EDU
to see reauth running
top -u brando9
- expt python script
python expts.py &
python -u ~/diversity-for-predictive-success-of-meta-learning/div_src/diversity_src/experiment_mains/main_sl_with_ddp.py --manual_loads_name sl_hdb1_5cnn_adam_cl_filter_size --filter_size 4 > $OUT_FILE 2> $ERR_FILE &
export JOB_PID=$!
echo JOB_PID = $JOB_PID
- Echo tmux id, should be jobid
tmux display-message -p '#S'
echo SLURM_JOBID = $SLURM_JOBID
- detach current tmux session
tmux detach &
- wait for pid from python to be done, if done kill this tmux sess
wait $JOB_PID
tmux ls
tmux kill-session -t $SLURM_JOBID
check it was killed
tmux ls
- Done
echo "Done with bash script (experiment or dispatched daemon experiments). "
As a side note, once the python script is running and been dispatched with &
, what I want is to kill the tmux session when that job is done. I tried that at the end but I suspect it won't work. I think it won't work because once it runs tmux detach &
it will go out of the tmux session and run the wait ...
command outside of tmux and block my main terminal. Instead what I want is to run that wait command inside of tmux (to not block me) and once the python script is done to kill the tmux session entirely. But that is just to add context to the final part of my script.
related: How does one authenticate with a command that requires your password in linux?