Ubuntu与Mac上的Linux不同吗?抱歉,如果这是个基本问题.我是新手。我正在尝试运行一个bash脚本,它用一些FASTQ文件创建一个.sh脚本。这可以在Mac操作系统上的终端上使用。我试图在我的Windows笔记本上运行它,它忽略了我对#s的逃避,只说找不到几个命令。我试过使用dos2unix,并与cat -A file.sh进行了反复检查,但这并没有帮助。
我试图运行的代码将所有fastq文件保存在一个文件夹中,并使用它们的文件名为SLURM作业提交创建一个.sh文件(我的学校的计算机集群需要它们,我需要制作100+作业脚本)。因此,Mac版本如下:
for FILE in *fastq; #change file type when needed (e.g., fasta, fastq, fastq.gz)
do echo -e \
\#\!/bin/bash \
\\n\#SBATCH --partition=nonpre \# Partition \(job queue\) \
\\n\#SBATCH --requeue \# Return job to the queue if preempted \
\\n\#SBATCH --job-name=samples \# Assign a short name to your job \
\\n\#SBATCH --nodes=1 \# Number of nodes you require \
\\n\#SBATCH --ntasks=1 \# Total \# of tasks across all nodes \
\\n\#SBATCH --cpus-per-task=64 \# Cores per task \(\>1 if multithread tasks\) \
\\n\#SBATCH --mem=180000 \# Real memory \(RAM\) required \(MB\) \
\\n\#SBATCH --time=72:00:00 \# Total run time limit \(HH:MM:SS\) \
\\n\#SBATCH --output=slurm.%N.${FILE}.out \# STDOUT output file \
\\n\#SBATCH --error=slurm.%N.${FILE}.err \# STDERR output file \(optional\) \
\\n \
\\n\#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION \
\\n \
\\nsacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j \$SLURM_JOBID \#this will get job run stats from SLURM\; use these to help designate memory of future submissions \
> ${FILE}.sh;
done在Windows上运行此程序时,我得到:
Slurm_Generator.sh: line 13: #!/bin/bash: No such file or directory
Slurm_Generator.sh: line 14: \n#SBATCH: command not found
Slurm_Generator.sh: line 16: \n#SBATCH: command not found
Slurm_Generator.sh: line 18: \n#SBATCH: command not found
Slurm_Generator.sh: line 20: \n#SBATCH: command not found
Slurm_Generator.sh: line 22: \n#SBATCH: command not found
Slurm_Generator.sh: line 24: \n#SBATCH: command not found
Slurm_Generator.sh: line 26: \n#SBATCH: command not found
Slurm_Generator.sh: line 28: \n#SBATCH: command not found
Slurm_Generator.sh: line 30: \n#SBATCH: command not found
Slurm_Generator.sh: line 32: \n#SBATCH: command not found
Slurm_Generator.sh: line 35: \n: command not found
Slurm_Generator.sh: line 36: \n#ADD: command not found
Slurm_Generator.sh: line 39: \n: command not found
Slurm_Generator.sh: line 40: \nsacct: command not found任何帮助都将不胜感激,并对Windows上的Ubuntu与Mac上的终端之间的区别做了一些解释。我尝试过研究这个问题,但是我一直在寻找没有解释的建议代码,或者这不是我的问题。谢谢!
编辑:我试着运行chmod +x script.sh,我会得到上面的错误。我跑错回音了吗?甚至运行:“对于*fastq中的文件;请回显-e,你好;完成”,Command 'hello' not found说
编辑:运行'bash file.sh‘将产生以下结果:bash file.sh生成以下内容(对于我的目录玩具中的5个.fastq文件):
Slurm_Generator.sh: line 8: #!/bin/bash: No such file or directory
Slurm_Generator.sh: line 9: \n#SBATCH: command not found
Slurm_Generator.sh: line 11: \n#SBATCH: command not found
Slurm_Generator.sh: line 13: \n#SBATCH: command not found
Slurm_Generator.sh: line 15: \n#SBATCH: command not found
Slurm_Generator.sh: line 17: \n#SBATCH: command not found
Slurm_Generator.sh: line 19: \n#SBATCH: command not found
Slurm_Generator.sh: line 21: \n#SBATCH: command not found
Slurm_Generator.sh: line 23: \n#SBATCH: command not found
Slurm_Generator.sh: line 25: \n#SBATCH: command not found
Slurm_Generator.sh: line 27: \n#SBATCH: command not found
Slurm_Generator.sh: line 30: \n: command not found
Slurm_Generator.sh: line 31: \n#ADD: command not found
Slurm_Generator.sh: line 34: \n: command not found
Slurm_Generator.sh: line 35: \nsacct: command not found如果我运行cat -A file.sh,我会在每一行的末尾看到一个$。即使我去掉了这些,我也得到了和上面一样的结果。运行ls -al script.sh gived:-rwxrwxrwx 1 cerberus cerberus 1209 Jun 16 00:17 Slurm_Generator.sh
编辑:我将脚本更改为:
#! /bin/bash
for FILE in *fastq; #change file type when needed (e.g., fasta, fastq, fastq.gz)
do echo -e \
"
#\!/bin/bash
#SBATCH --partition=nonpre # Partition (job queue)
#SBATCH --requeue # Return job to the queue if preempted
#SBATCH --job-name=samples # Assign a short name to your job
#SBATCH --nodes=1 # Number of nodes you require
#SBATCH --ntasks=1 # Total # of tasks across all nodes
#SBATCH --cpus-per-task=64 # Cores per task (>1 if multithread tasks)
#SBATCH --mem=180000 # Real memory (RAM) required (MB)
#SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
#SBATCH --output=slurm.%N.${FILE}.out # STDOUT output file
#SBATCH --error=slurm.%N.${FILE}.err # STDERR output file (optional)
#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION \
sacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j \$SLURM_JOBID \#this will get job run stats from SLURM\; use these to help designate memory of future subm$" \
> ${FILE}.sh;
done我的新输出如下(这要好得多):
#\!/bin/bash
#SBATCH --partition=nonpre # Partition (job queue)
#SBATCH --requeue # Return job to the queue if preempted
#SBATCH --job-name=samples # Assign a short name to your job
#SBATCH --nodes=1 # Number of nodes you require
#SBATCH --ntasks=1 # Total # of tasks across all nodes
#SBATCH --cpus-per-task=64 # Cores per task (>1 if multithread tasks)
#SBATCH --mem=180000 # Real memory (RAM) required (MB)
#SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
#SBATCH --output=slurm.%N.Sample1.fastq.out # STDOUT output file
#SBATCH --error=slurm.%N.Sample1.fastq.er # STDERR output file (optional)
#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION
sacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j $SLURM_JOBID \#this will get job run stats from SLURM\; use these to help designate memory of future submissions我遇到的唯一问题是,当它打印出每个.fastq文件(这就是我想要的)时,它输出的结果.sh文件是空的。因此,它没有识别脚本的> ${File}.sh部分。
谢谢大家!
发布于 2021-06-28 23:35:45
我意识到我必须在\之前添加一个> ${File}.sh。所以答案是:
#! /bin/bash
for FILE in *fastq; #change file type when needed (e.g., fasta, fastq, fastq.gz)
do echo -e \
"
#\!/bin/bash
#SBATCH --partition=nonpre # Partition (job queue)
#SBATCH --requeue # Return job to the queue if preempted
#SBATCH --job-name=samples # Assign a short name to your job
#SBATCH --nodes=1 # Number of nodes you require
#SBATCH --ntasks=1 # Total # of tasks across all nodes
#SBATCH --cpus-per-task=64 # Cores per task (>1 if multithread tasks)
#SBATCH --mem=180000 # Real memory (RAM) required (MB)
#SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
#SBATCH --output=slurm.%N.${FILE}.out # STDOUT output file
#SBATCH --error=slurm.%N.${FILE}.err # STDERR output file (optional)
#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION \
sacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j \$SLURM_JOBID \#this will get job run stats from SLURM\; use these to help designate memory of future subm$" \
> ${FILE}.sh;
done发布于 2021-06-16 04:57:42
改为使用本文档:
for FILE in *fastq; #change file type when needed (e.g., fasta, fastq, fastq.gz)
do
cat <<-EOF > ${FILE}.sh
#!/bin/bash
#SBATCH --partition=nonpre # Partition (job queue)
#SBATCH --requeue # Return job to the queue if preempted
#SBATCH --job-name=samples # Assign a short name to your job
#SBATCH --nodes=1 # Number of nodes you require
#SBATCH --ntasks=1 # Total # of tasks across all nodes
#SBATCH --cpus-per-task=64 # Cores per task (>1 if multithread tasks)
#SBATCH --mem=180000 # Real memory (RAM) required (MB)
#SBATCH --time=72:00:00 # Total run time limit (HH:MM:SS)
#SBATCH --output=slurm.%N.${FILE}.out # STDOUT output file
#SBATCH --error=slurm.%N.${FILE}.err # STDERR output file (optional)
#ADD WHATEVER CODE YOU WANT HERE AS YOUR SLURM JOB SUBMISSION
nsacct --format=JobID,JobName,NTasks,NNodes,NCPUS,MaxRSS,AveRSS,AveCPU,Elapsed,ExitCode -j \$SLURM_JOBID #this will get job run stats from SLURM; use these to help designate memory of future submissions
EOF
donehttps://askubuntu.com/questions/1346161
复制相似问题