1

I believe my problem is similar as found here but I was confused by the reply (and I can't comment in this question yet due to my low rep).

I have a bash script I need to run using slurm, so when the script needs input from the user, such as this:

Enter y or yes if you want to continue Compass and used cached results.

The script stops. This line shows up after this line of code runs:

compass --data compass_adipocytes_only_input_transposed.tsv --num-processes 10 --species mus_musculus

What can I do to make my script reply this with "y"?

This is the entire script

#!/usr/bin/env bash
#SBATCH --job-name=Compass
#SBATCH --ntasks=54
#SBATCH --output=compass.%j.out
#SBATCH --exclusive

# To activate this environment, use
. /tools/Miniconda3.7/etc/profile.d/conda.sh
conda activate /data04/projects04/MarianaBoroni/lbbc_members/lib/conda_envs/compass

which compass


compass --data compass_adipocytes_only_input_transposed.tsv --num-processes 10 --species mus_musculus
yes | compass

# To deactivate an active environment, use:
conda deactivate
exit

I executed it with the command

sbatch metabolismanalysis.sh
  • The Compass tool also says "Warning: The arguments used in the temporary directory [...] are different from current arguments. Cached results may not be compatible with current settings" followed by the message that you quote, and then "Otherwise rerun Compass after removing/renaming the temporary directory or changing the --temp-dir argument". This indicates that you might possibly get invalid results as the cached data was created with different parameters from what you are using now. Would it not be better to make sure that the old cache was cleared? – Kusalananda Aug 03 '21 at 16:40
  • the other times I tried this (without slurm) it rewrote the files of previous runs, this wouldn't be a problem in my case, thank you for pointing that out! – Diogo de Moraes Aug 03 '21 at 16:52
  • Read the man page for `compass`. Does it have an option to assume that "yes" is the answer to that question? (some, but certainly not all programs have options like that - e.g. apt has a `-y` aka `--yes` aka `--assume-yes` option). If compass has such an option, then use it. For non-interactive/batch operations, it's best to avoid relying on user input wherever possible, rather than faking it with a program like `yes`. – cas Aug 04 '21 at 05:55

1 Answers1

0
yes | myscript.sh

This will output a continuous stream of y\n for your script. If you need a different character/string, use yes foo to output foo. See yes man page

blackbrandt
  • 142
  • 5
  • thanks! so I just put this anywhere in my script? this is what I was confused about in the other thread I linked – Diogo de Moraes Aug 03 '21 at 16:42
  • The command that needs the continuous stream of `y`'s should be run as above. This could either be your myscript.sh file and you run it at the terminal `$ yes | myscript.sh`, or it could be a command in your script. It's up to you to figure out how to implement it as we don't have enough details here. – blackbrandt Aug 03 '21 at 16:45
  • 1
    They mean `yes | compass ...`. – Kusalananda Aug 03 '21 at 16:46
  • Ah, i missed that. Thanks @Kusalananda. – blackbrandt Aug 03 '21 at 16:51
  • Thank you! I tried both ways, but it seems I'm getting EOF error, which seems to be a lack of user input. I edited my question with the full code I tried – Diogo de Moraes Aug 03 '21 at 16:59
  • @DiogodeMoraes What I meant was put `yes |` in front of your ordinary `compass` command with all its options etc. I used `...` in my previous comment to mean "the rest of your `compass` command". – Kusalananda Aug 03 '21 at 17:33
  • I feel really dumb now! thank you very much! it seems it worked! – Diogo de Moraes Aug 04 '21 at 05:36
  • @DiogodeMoraes if the answer helped you please click the green check mark and/or upvote the answer. – blackbrandt Aug 04 '21 at 13:15