Skip to main content
add script
Source Link
rudib
  • 1.8k
  • 1
  • 20
  • 41

You can use this in a script like that:

#!/bin/sh

cat  << EOF
<table>
    <thead>
        <tr>
            <th>ver</th>
            <th>link</th>
            <th>modified</th>
            <th>size</th>
        </tr>
    </thead>
    <tbody>
EOF

$i=1

cat urls.list | while read url
do
        file_info=$(curl -s --head "$url")
        last_modified=$(echo "$file_info" | grep Last-Modified | cut -c16- | tr -d '\r\n')
        content_length=$(echo "$file_info" | grep Content-Length | cut -c17- | tr -d '\r\n')

cat  << EOF
        <tr>
            <td>1.0.$i</td>
            <td><a href="$url">download</a></td>
            <td>$last_modified</td>
            <td>$content_length</td>
        </tr>
EOF
let "i++"
done

cat << EOF
    </tbody>
</table>
EOF

You need to create a file called urls.list which should conatain one url per line. Like that:

http://speedtest.newark.linode.com/100MB-newark.bin
http://speedtest.tokyo2.linode.com/100MB-tokyo2.bin

Running the script will produce an output like that:

<table>
    <thead>
        <tr>
            <th>ver</th>
            <th>link</th>
            <th>modified</th>
            <th>size</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1.0.1</td>
            <td><a href="http://speedtest.newark.linode.com/100MB-newark.bin">download</a></td>
            <td>Thu, 01 Aug 2019 16:35:25 GMT</td>
            <td>104857600</td>
        </tr>
    </tbody>
</table>

If you need a specific version name, you could store that in the list file with a seperator (e.g.: version name|url). And would need to adjust the code a bit. Now, it just follows the order of the url list.

You can use this in a script like that:

#!/bin/sh

cat  << EOF
<table>
    <thead>
        <tr>
            <th>ver</th>
            <th>link</th>
            <th>modified</th>
            <th>size</th>
        </tr>
    </thead>
    <tbody>
EOF

$i=1

cat urls.list | while read url
do
        file_info=$(curl -s --head "$url")
        last_modified=$(echo "$file_info" | grep Last-Modified | cut -c16- | tr -d '\r\n')
        content_length=$(echo "$file_info" | grep Content-Length | cut -c17- | tr -d '\r\n')

cat  << EOF
        <tr>
            <td>1.0.$i</td>
            <td><a href="$url">download</a></td>
            <td>$last_modified</td>
            <td>$content_length</td>
        </tr>
EOF
let "i++"
done

cat << EOF
    </tbody>
</table>
EOF

You need to create a file called urls.list which should conatain one url per line. Like that:

http://speedtest.newark.linode.com/100MB-newark.bin
http://speedtest.tokyo2.linode.com/100MB-tokyo2.bin

Running the script will produce an output like that:

<table>
    <thead>
        <tr>
            <th>ver</th>
            <th>link</th>
            <th>modified</th>
            <th>size</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1.0.1</td>
            <td><a href="http://speedtest.newark.linode.com/100MB-newark.bin">download</a></td>
            <td>Thu, 01 Aug 2019 16:35:25 GMT</td>
            <td>104857600</td>
        </tr>
    </tbody>
</table>

If you need a specific version name, you could store that in the list file with a seperator (e.g.: version name|url). And would need to adjust the code a bit. Now, it just follows the order of the url list.

Source Link
rudib
  • 1.8k
  • 1
  • 20
  • 41

This will return the file information you can get from the header:

curl --head http://speedtest.newark.linode.com/100MB-newark.bin

It will return:

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 28 Sep 2019 12:47:03 GMT
Content-Type: application/octet-stream
Content-Length: 104857600
Last-Modified: Thu, 01 Aug 2019 16:35:25 GMT
Connection: keep-alive
ETag: "5d4314cd-6400000"
Accept-Ranges: bytes

If that is what you need, you can write a bash script to generate a table/html file with that information.