2

This is my script:

#!/bin/bash

curl -X POST -T /this/is/my/path/system.log https://whatever;

As you see, I am using a file called system.log. How can I do that for the complete /this/is/my/path/ path in a loop? There are about 50 files in /this/is/my/path/ which I want to use with curl.

Thanks!

user1856596
  • 7,027
  • 10
  • 41
  • 63

2 Answers2

3

You can upload multiple files using this range syntax in curl:

$ curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com
Engineer2021
  • 3,288
  • 6
  • 29
  • 51
2

A very robust solution is to iterate through a for loop. Moreover you can take advantage of this and insert echo commands or delete, or whatever command you want.

#!/bin/bash

for file in /this/is/my/path/*
do
    curl -X POST -T "/this/is/my/path/$file" https://whatever;
done; # file
Raul Luna
  • 1,945
  • 1
  • 17
  • 26
  • 2
    Something like this could be made to work, but `$file` will probably include the whole path (at least on my OS) so you should not need to repeat the path when using the variable... Also, if there are any folders in the path, it is going to get complicated and probably fail. – beroe May 09 '14 at 02:44
  • Nice solution but $file carries the whole path, no need for the prefix! (bash 5, arch linux) – gyorgyabraham May 27 '20 at 11:43