在上一篇【已解决】shell大法好——用here document生成脚本中介绍了如何使用here document自动生成脚本文件,折腾了一番,搞定了新的create_newcase.sh,可以自动生成pbs文件啦,不用每次调核心数调节点调路径啦。话说shell的if语法真是折腾,调试了快半个小时才通过三行if语句。注意各种空格!
核心代码:
97 #Deal with que and nodes 98 NNODES=$[NTASKS/16] 99 100 if [ $QUENAME = "ys" ]; then 101 WALLTIME=999 102 elif [ $QUENAME = "few" ]; then 103 WALLTIME=720 104 elif [ $QUENAME = "medium" ]; then 105 WALLTIME=168 106 else 107 WALLTIME=48 108 fi 109 110 #-------------------------------------- 111 #------Now generate the pbs file------- 112 #-------------------------------------- 113 cat << EOF > run.pbs 114 #!/bin/sh 115 #PBS -N $CASENAME 116 #PBS -q $QUENAME 117 #PBS -l walltime=$WALLTIME:00:00 118 #PBS -l nodes=$NNODES:ppn=16 119 #PBS -r n 120 #PBS -o cesmrun.log 121 #PBS -e cesmrun.err 122 echo "This jobs is "\$PBS_JOBID@\$PBS_QUEUE 123 MPIBIN=/public/mpi/mvapich2-18-intel/bin 124 EXEROOT=/users/yangsong3/L_Zealot/F/$CASENAME/exe 125 cd \$EXEROOT 126 \$MPIBIN/mpirun -np $NTASKS -hostfile \$PBS_NODEFILE ./cesm.exe >& ../run.log 127 EOF