I have a "command" text file that issues a data file download command on each line. I send the command file to bash. However, a small percentage of the downloads fail. Here is the algorithm I use to find out what's missing:
- After downloading, I go back through the command file and check if each download file exists.
- If the download doesn't exist, I copy the command line into a new command file.
- I am left with a new command file for the remaining downloads.
Here is the bash script I implemented the algorithm with:
1 #!/bin/bash 2 while read line 3 do 4 for item in $line 5 do 6 if [[ $item == *out_fname* ]]; then 7 splitline=(${item//=/ }) 8 target_file=${splitline[1]} 9 if [ ! -f $target_file ]; then 10 echo $line >> stillneed.txt 11 fi 12 fi 13 done 14 done < "$@" Question: This works well, but is there a better algorithm or implementation (maybe using something other than bash)? What I did was just have bash do what a human would have to do. But it seems Unix always has a better way of doing things...
out_fname=myfile.txtis the relevant command-line argument< "$@"will fail with more than 1 arg.