Bash script jumping too quickly to the next command - crash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash script jumping too quickly to the next command - crash
# 1  
Old 05-17-2016
Linux Bash script jumping too quickly to the next command - crash

Hi, (I am not too good in command-lines).

I am running a bash script and at some point my loop starts to run super quickly. Then, the steps after do not get processed and there is no further outpout generated. I tried with the sleep 20s option, as I thought some steps would get overlapped, but it did not solve the issue.

The last command line before it crashes is done with Mothur, and the following which is problematic is to generate a metadata for qiime commands. Although it is not in the qiime environment yet, so the dependencies should not be affected.

Also, When I run the script up to this specific step, then manually launch the next part of the script, no problem occurs.
What is going on here?Smilie
Thanks a lot
# 2  
Old 05-17-2016
We can't possibly say without actually seeing your code.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 05-18-2016
Linux

Hi,
the last step to work correctly is:

Code:
for f in $(find "$trimmed" -type f | grep -F ".fasta" | grep -v -F ".scrap.fasta") # -v -> exclude
do
  sed -i 's/%[^:]*//' "$f"
done



Then, the next step which is the issue from is that;

Code:
custom=$(echo "${customFields[@]}" | sed -e 's/ /\\t/g') #add custom
echo -e "#SampleID\tBarcodeSequence\tLinkerPrimerSequence\tInputFileName\t"${custom}"\tDescription" > "${metadata}"/metadata.tsv

for g in $(find "$trimmed" -type f | grep "fasta" | grep -v "scrap") # -v -> exclude
do
  name=$(basename "$g")
  nameNoExt="${name%.*}"
  #create array: a=(1 2 3 4)
  #show content of array: echo "${a[@]}"
  #t="${nameNoExt//-/ }"
  #params=("${nameNoExt//-/ }") #${string//substring/replacement}
  #echo "${params[@]}"
  param1=$(cut <<< "$nameNoExt" -d "-" -f 1) #equals $(echo "$nameNoExt" | cut -d "-" -f 1)
  param2=$(cut <<< "$nameNoExt" -d "-" -f 2)
  param3=$(cut <<< "$nameNoExt" -d "-" -f 3 | sed -e 's/Run//') #only keep the number of the run

  tempLine=$(cat "$barcode" | grep "$param1" | grep "$param2" | grep "$param3")
  echo "$tempLine" | awk -v fileName="$name" -v sampleName="$its" -F $'\t' 'BEGIN {OFS = FS} {print $1, $3, $4, fileName, $6, $7, $8, $9, $10, $1"-"sampleName}' >> "${metadata}/metadata.tsv"
done





Thanks a lot Smilie

Last edited by vgersh99; 05-18-2016 at 02:58 PM.. Reason: too early for the christmas trees - please use code tags!
# 4  
Old 05-19-2016
Debug script by setting xtrace and verbose:-
Code:
#!/bin/bash -xv

# 5  
Old 05-19-2016
And what happens when this code is run?

What should be happening instead?

What do you mean by "crash"?

Does it print any error messages?

I can't see your computer from here, I have none of your data to test with, please be specific Smilie
# 6  
Old 05-19-2016
Hi,
thanks for the help.

Yoda;
I tried running the code #!/bin/bash -xv
and I got no information from it...
Maybe I am not doing it right but I see no text or output files from the problem.

Corona;
When this code is run all in one shot, I know that it stops at the step I mentioned above because the output files are not generated. BUT; when I run each steps one by one, it is all good... ( Smilie).

Instead, I would like it to run this next step where the ''pipeline'' just seem to run but doing nothing.

By crash, I mean it generates all the first files normally and then, it starts printing through the next steps way too quickly (one of them takes at least 1h normally) and that, up to the last step. I thens stays stuck there as if it was trying to process it still but I know it is not. I have waited for it, and I get no output files.

No error message appears and I am not able to make one appear...Smilie.

I hope this is more clear...

Last edited by Scrutinizer; 05-19-2016 at 04:40 PM..
# 7  
Old 05-19-2016
Check what value $trimmed is and then if you run just the whole find command with the value stated, do you get any output? My suspicion is that you are not matching anything, therefore your script just carries on, i.e. the for g in ..... has nothing else on the line.

Of course, $trimmed may be null/invalid and your find will error so that could be another cause.


Does that help?

It would be useful to see your output pasted within CODE tags, naturally.


Kind regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need bash script to use a sed command as a variable

I need to be able to use a sed command as a variable in a bash script. I have the sed command that almost works the way I want it. the command is sed -n '/inet/,/}/p' config.boot This gets me this result: inet 192.168.1.245 } I need to get the IP address into a variable so I... (9 Replies)
Discussion started by: edlentz
9 Replies

2. Shell Programming and Scripting

New bash menu printing errors but closes too quickly

I am beginning to write a new version of the bash menu below. The previous version worked great and now when I start the updated bash it opens and a some lines print in the terminal and it closes quickly. I know there are errors but how can I see them or fix them, I tried set -x with the same... (12 Replies)
Discussion started by: cmccabe
12 Replies

3. Shell Programming and Scripting

How to ignore error in command in bash script?

Hello, i have bash script where im cycling some command for different lines in external file. example: while read domain;do nslookupout=$(nslookup -type=ns $domain) || true another commands done < filenamewithdomains i added: || true after the command in belief it will just skip... (6 Replies)
Discussion started by: postcd
6 Replies

4. Shell Programming and Scripting

BASH SCRIPT of LS command

I need help in writing a BASH SCRIPT of ls command. for example: $ ./do_ls.sh files f1.txt f2.jpeg f3.doc $ ./do_ls.sh dirs folder1 folder2 folder3 My attempt: #!/bin/bash # if test $# -d file then echo $dirs else (3 Replies)
Discussion started by: above8k
3 Replies

5. Solaris

jumping from one line to another

Hi, Thanks (10 Replies)
Discussion started by: rocky1954
10 Replies

6. Shell Programming and Scripting

Piping output from a command into bash script

Hi all. I am using procmail to deliver an email to a script I am developing. Procmail delivers the email to the script on standard input. I imagine this is the same as piping input from a command into the script. Hence I've been testing my script by running echo 'test' | sms-autosend-backup.sh ... (2 Replies)
Discussion started by: akindo
2 Replies

7. Shell Programming and Scripting

work area directory jumping script?

hi all, Ive been trying to find some way of doing this for ages but i have is a shell script that activates a python search and there it no tab completion. more familliar with tcsh at the moment but i'm a newbe. i was trying to make an easy way to browse to a list of working directories. ... (0 Replies)
Discussion started by: jvan
0 Replies

8. UNIX for Dummies Questions & Answers

need solution for this quickly. please quickly.

Write a nawk script that will produce the following report: ***FIRST QUARTERLY REPORT*** ***CAMPAIGN 2004 CONTRIBUTIONS*** ------------------------------------------------------------------------- NAME PHONE Jan | ... (5 Replies)
Discussion started by: p.palakj.shah
5 Replies

9. Shell Programming and Scripting

script to loop and check jumping seq.

Hi, Normally, I will manually to use "ll" command to list the following file from \FILE\CACHE\ directory and check the jump seq. Can I write a script to loop or/and check jump seq file (if jumped seq and show "missing seq no" message for me) -rw-rw----+ 1 user develop 14012 Sep 4... (1 Reply)
Discussion started by: happyv
1 Replies

10. Shell Programming and Scripting

Linux Os Crash Script

How can I simulate a Linux OS crash without damaging the OS? I am performing an os watchdog test that sends out an alert once the timer expires. (1 Reply)
Discussion started by: cstovall
1 Replies
Login or Register to Ask a Question