Отличается ли Ubuntu от Linux на Mac? Извините, если это основной вопрос... Я новичок в этом. Я пытаюсь запустить сценарий bash, который создает сценарий .sh из некоторых файлов FASTQ. Это работает в терминале на Mac OS. Я пытаюсь запустить его на ноутбуке с Windows, и он игнорирует мое экранирование #s и просто говорит, что несколько команд не найдены. Я пробовал использовать dos2unix
и дважды проверял с помощью cat -A file.sh
, но это не помогло.
Код, который я пытаюсь запустить, берет все файлы fastq в папке и создает файл .sh для отправки заданий SLURM, используя их имя файла (необходимо для компьютерного кластера моего университета, и мне нужно сделать 100+ сценариев заданий). Итак, версия для Mac OS выглядит следующим образом:
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
Любая помощь была бы признательна, и некоторые объяснения, в чем разница между Ubuntu на Windows и Терминалом на Mac. Я пробовал исследовать это, но я продолжаю находить предложенный код без объяснений, или это не совсем моя проблема. Спасибо!
Edit: Я попробовал запустить chmod +x script.sh
и я получу вышеуказанные ошибки. Может я неправильно выполняю 'echo'? Даже если запустить:
'for FILE in *fastq;
do
echo -e
hello;
done'
говорит Команда 'hello' не найдена
Edit: Running 'bash file.sh' yields the following:
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
дало: -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
часть сценария.
Edit [SOLVED]:
Мне пришлось добавить \
перед строкой, в которой говорится > ${File}.sh
Спасибо всем!
Я понял, что мне нужно добавить \
перед > ${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
Используйте вместо него heredoc:
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
done