强制 shell 脚本按顺序执行 运行 任务

Force shell script to run tasks in sequence

我正在 运行ning 一个 shell 脚本来执行多个任务。问题是脚本不会等待任务结束后再开始下一个任务。我的脚本应该以不同的方式工作,在下一个任务开始之前等待一个任务完成。有没有办法做到这一点?我的脚本看起来像这样

sbatch retr.sc 19860101 19860630
scp EN/EN1986* myhostname@myhost.it:/storage/myhostname/MetFiles

第一个命令运行s retr.sc,检索文件,大约需要半个小时。不过,第二个命令是 运行 right soon,仅将一些文件移动到目标位置。我希望 scp 命令仅在第一个完成时才为 运行。

提前致谢

sbatch 在将作业提交到 slurm 后立即退出。

salloc 将在退出前等待作业完成。

来自手册页:

$ salloc -N16 xterm
salloc: Granted job allocation 65537
(at this point the xterm appears, and salloc waits for xterm to exit)
salloc: Relinquishing job allocation 65537

您有多种选择:

  • 使用srun而不是sbatchsrun retr.sc 19860101 19860630
  • 第二个命令也使用 sbatch,并使其依赖于第一个

像这样:

RES=$(sbatch retr.sc 19860101 19860630)   
sbatch --depend=after:${RES##* } --wrap "scp EN/EN1986* myhostname@myhost.it:/storage/myhostname/MetFiles"
  • 创建一个包含 retr.scscp 的脚本并提交该脚本。

感谢您的回复

我是这样整理的

RES=$(sbatch retr.sc $date1 $date2)
array=(${RES// / })
JOBID=${array[3]}
year1={date1:0:4}
sbatch --dependency=afterok:${JOBID}  scp.sh $year1

其中 scp.sh 是用于将文件传输到我的本地计算机的脚本