-2

I am new to bash. I am working on a project on a HPC sever, and having some trouble in changing a dynamic file into static.

I have created an alias "submitjob" Its tasks are:

  1. take a user input "job_ID"
  2. create a copy of generic slurm script - "submission_script_job_ID"
  3. submit this new slurm script (submission_script_job_ID) onto the cluster

alias submitjob='echo "What is the job_ID?"; read job_ID;cp /home/Shubham/generic_slurm_script.sh ./submission_script_$job_ID.sh; echo "Status: Submission script for $job_ID is created."; sbatch submission_script_${job_ID}.sh $job_ID; echo "Status: $job_ID submitted sucessfully."'

Snippet of the generic script:

#!/bin/bash

job_ID=$1

.
.
.

time /opt/apps/gaussian09/g09l/g09/g09 ./${job_ID}.com  >./${job_ID}.log

This is working fine, but the problem is the new "submission_script_job_ID" is again dynamic, i.e. it needs the job_ID to run. Basically, it is just a copy of a generic file with a different file name. I want to change something in the code to make this new script static, i.e. instead of "job_ID.com" it should fill it with the input we provided earlier (job_ID). Is there a way to do that. I'm not sure if there is a way to edit this new script in the alias code itself. Any help/suggestion would be great. Thanks!!

Jetchisel
  • 7,493
  • 2
  • 19
  • 18
  • That is change the sbatch input to something like: "sbatch submission_script_${job_ID}.sh" as this "script" is static in nature and already contains the job name. Hope this makes sense. – Shubham Gupta Aug 22 '21 at 16:40

1 Answers1

0

I want to change something in the code to make this new script static, i.e. instead of "job_ID.com" it should fill it with the input we provided earlier (job_ID).

If you have envsubst, you can use it instead of the cp command:

… export job_ID; envsubst '$job_ID' </home/Shubham/generic_slurm_script.sh >submission_script_$job_ID.sh; …

If you haven't, you can do something similar with sed.

Armali
  • 18,255
  • 14
  • 57
  • 171