首页 > 解决方案 > 意外的 EOF 在第 1 行中寻找匹配的 `"'...。什么给出了?

问题描述

我在集群计算系统上运行以下 slurm 脚本。

#!/bin/bash
#
#SBATCH --job-name=R1.5-CG-nvtrun            # create a short name for your job
#SBATCH --qos=short                   # _quality of service_
#SBATCH --nodes=1                     # node count
#SBATCH --ntasks-per-node=12          # number of tasks per node
#SBATCH --cpus-per-task=1             # cpu-cores per task (>1 if multi-threaded tasks)
#SBATCH --mem=10GB                   # total memory requested
##SBATCH --mem-per-cpu=4G              # memory per cpu-core (4G per cpu-core is default)
#SBATCH --gres=gpu:1                  # number of gpurs per node
#SBATCH --time=7:00:00                # total run time limit (HH:MM:SS)
#SBATCH --mail-type=all               # send email on job start, end, and fail

# The modules I need to run my job
module purge
module load intel/19.0/64/19.0.5.281    # for running gromacs
module load anaconda3/2020.7
conda activate data-analysis
# run the job

set -e


# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG

# echo an error message before exiting
trap 'echo "\"${last_command\" command filed with exit code $?."' EXIT

init=InitializeSystem
em=EnMinimization
nvt=NVT-Equilibration
npt=NPT-Equilibration
md=MolDynamics

for iteration in {1..5}
do 
    echo "iteration number $iteration" 
    echo "setting up editconf..."
    # construct a box using editconf
    gmx editconf -f ./${init}/BZCG.gro -o ./${init}/BZCG-in-box.gro -c -d 1.0 -bt cubic > ./${init}/editconf.txt 2>&1
    echo "executed editconf!" 

    echo "setting up insert molecules..."
    # insert 1000 molecules in a box 
    gmx insert-molecules -box 4.48 4.48 4.48 -ci ./${init}/BZCG-in-box.gro -nmol 600 -o ./${init}/BZCG-setup.gro > ./${init}/insert-molecules1.txt 2>&1 
    echo "executed insert molecules!" 

    echo "setting up grommp for em..."
    # run a minimization script
    gmx grompp -f ./${em}/minim.mdp -c ./${init}/BZCG-setup.gro -p ./${init}/topol.top -o ./${em}/BZCG-EnMinimized > ./${em}/grompp_em.txt 2>&1
    echo "executed grommp em!" 

    echo "setting up mdrun for em..."
    # run the molecular dynamics 
    gmx mdrun -v -deffnm ./${em}/BZCG-EnMinimized > ./${em}/mdrun_em.txt 2>&1 
    echo "executed mdrun for em!" 

    echo "setting up grommp for nvt..."
    # run an NVT script 
    gmx grompp -f ./${nvt}/nvt.mdp -c ./${em}/BZCG-EnMinimized.gro -r ./${em}/BZCG-EnMinimized.gro -p ./${init}/topol.top -o ./${nvt}/BZCG-NVT-Eqbrt.tpr > ./${nvt}/grompp_nvt.txt 2>&1
    echo "executed grommp for nvt!"

    echo "setting up mdrun for nvt..."
    # run the molecular dynamics 
    gmx mdrun -v -deffnm ./${nvt}/BZCG-NVT-Eqbrt > ./${nvt}/mdrun_nvt.txt 2>&1 
    echo "executed mdrun for nvt!"

    echo "moving onto production..." 

    # run the production script 
    echo "setting up grommp for production run..."
    gmx grompp -f ./${md}/md.mdp -c ./${nvt}/BZCG-NVT-Eqbrt.gro -t ./${nvt}/BZCG-NVT-Eqbrt.cpt -p ./${init}/topol.top -o ./${md}/BZCG-MolDynamics.tpr -maxwarn 1 > ./${md}/grompp_production.txt 2>&1
    echo "executed grommp for production run!" 

    echo "setting up mdrun for production run..."
    # run the molecular dynamics 
    gmx mdrun -v -deffnm ./${md}/BZCG-MolDynamics > ./${md}/mdrun_production.txt 2>&1 
    echo "executed production run!" 

    echo "start creating the rdf..."

    gmx rdf -f ./${md}/BZCG-MolDynamics.xtc -s ./${md}/BZCG-MolDynamics.tpr -o rdf_.xvg -selrpos whole_mol_com -seltype whole_mol_com -cut 0 -rmax 2.226 << EOF
    2
    2
EOF

    echo "rdf created!" 

    echo "deleting back-ups..."

    for dir in ${init} ${em} ${nvt} ${npt} ${md}
    do
        rm ./$dir/\#* || true 
    done 

    rm \#* || true
    echo "deleted back-ups!"
    
    # run the analysis, update parameters 
    python update.py
done 

我正在运行的所有gmx东西都是一个名为 gromacs 的软件包。

这个脚本的奇怪之处在于它按预期运行所有内容,它进行了 10 次迭代,但是一旦完成,它会输出一条错误消息: /var/spool/slurmd/job6141167/slurm_script: exit trap: line 1: unexpected EOF while looking for matching `"'

第 1 行怎么可能不匹配"

我在下面的未缩进 EOF

2
2

似乎是该程序完成我想要它做的工作的唯一方式。如果我在此处取消缩进 EOF,则会收到以下错误:

/var/spool/slurmd/job6141905/slurm_script: line 104: warning: here-document at line 84 delimited by end-of-file (wanted `EOF')
/var/spool/slurmd/job6141905/slurm_script: line 105: syntax error: unexpected end of file
/var/spool/slurmd/job6141905/slurm_script: exit trap: line 1: unexpected EOF while looking for matching `"'

这里错误的性质是什么,我该如何解决?您对我的任何建议将不胜感激。

标签: bashslurm

解决方案


你有一个缺失}的行

trap 'echo "\"${last_command\" command filed with exit code $?."' EXIT
                            ^

这可能是触发该错误的原因。


推荐阅读