0

I have about 100 lists of URLs used for health checking (200, 300,400,500) but cannot figure out the terminology to ask the question. In advance, I apologize.

I want to use a list to choose on of the identified list files, containing the URLS, and then run curl against it to get my results. Currently, Im stumped.

If I call out the file implicitly, I can get things to work. If I use a select againt the listing of files to choose from, I can get that file and do a simple 'cat' of the result and get the URL's in it successfully.

I cannot seem to do the select, get the file into its variable and then make the next move to the loop to run thru those items in the chosen file successfully.

Im embarrased that its making a mess out of my hair.

works

select f in *.lst; do echo $f
done

Does not work in any way or format

select f in *.lst;
for i in (cat $f); do curl $i
done

 bash -x ./test.sh 
+ select f in '*.lst'
1) availability_health_check.lst      3) facility_service_health_check.lst
2) explorer_health_check.lst          4) mobile_service_health_check.lst
#? 1
+ echo availability_health_check.lst
availability_health_check.lst
  • Have a read through mywiki.wooledge.org/BashFAQ/001 to properly read the lines of a file. – glenn jackman Aug 12 at 20:11
  • You'd need to tell us how the files (URLs in the files?) are to be selected for checking . As it stands, your script snippet looks fine if you want to run all. – vonbrand Aug 12 at 20:21
0

Your code is missing a do and done for your select statement. I believe you want something like this:

select f in *.lst; do
        for i in $(cat $f); do
                curl "$i"
        done
done

This will allow you to select a file, then curl is ran on each line in the selected file. Add an exit 0 after the for loop if want the script to exit after you've selected a file.

  • BINGO!!! Thanks. Sometimes it is hard to see the trees for the forest. – Stryker Cain Aug 13 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.