how do you use user inputs with slurm?

You have two options:

Modify the script so that it uses parameters rather than interactive questions.

The script would then look like this:

#!/bin/bash

mypath=${1?Usage: $0 <mypath> <archive_name>}
archive_name=${2?Usage: $0 <mypath> <archive_name>}    

echo Ok, let\'s create the archive $archive_name

for i in $mypath/*;
do if [[ -f $i ]]; then
   tar -cvf $archive_name $mypath/*;
   fi;
done

This script would then be run with bash my_script.sh /the/path/of/the/files my_archive.tar rather than bash my_script.sh . The first argument is made available in the $1 variable in the script, the second one is in $2, etc. See this for more info.

The syntax $(1?Usage...) is a simple way to issue an error message if the script is not run with at least two arguments. See this for more information

or,

Use Expect to answer the questions automatically

The expect command is (from the doc)

a program that “talks” to other interactive programs according to a script.

You could use an Expect script like this:

#!/usr/bin/expect
spawn my_script.sh
expect "What's the path of the files?"
send "/the/path/of/the/files\r"
expect -re "What's the name you want to give to your archive with the files of .*"
send "my_archive.tar\r"
expect

It gives the following, after making the Expect script executable:

$ ./test.expect 
spawn my_script.sh
What's the path of the files?
/the/path/of/the/files
What's the name you want to give to your archive with the files of /the/path/of/the/files?
my_archive.tar
Ok, let's create the archive my_archive.tar

You can run the Expect script in a Slurm submission script.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top