Save files and save file hash values using Linux curl

Asked 2 years ago, Updated 2 years ago, 38 views

After automatically downloading a file in the format img_%03d.jpg from a web server called http://www.test.org/download/, use md5 to obtain a hash

img_001.jpg: hash value
img_002.jpg : hash value
...

I'm writing code to save it to a file like this, but I don't know how to squeeze the middle part...

I wrote it up to here, but how do I write the code after do to save it as above in the test.lst file? Is there anything wrong with the code I wrote? I'd appreciate it if you let me know.

#!/bin/sh

url_path="http://www.test.org/download/"
file_name="img_%03d.jpg"

for i in $(seq 10)
do
    curl -sO "${url_path}${file_name}"  && url=$(printf "$file_name : " $i, md5sum "$file_name") >  test.lst
done

linux

2022-09-20 20:01

1 Answers

#!/bin/bash
url_path="test/"
file_name="img_%03d.jpg"

for i in $(seq 10)
do
        file=$(printf "$file_name" "$i")
        echo $url_path$file // curl ...
        md5sum ${file} | awk '{ print $2 " : " $1 >> "list.lst" }'
done

/// /// list.lst
img_001.jpg : d8e8fca2dc0f896fd7cb4cb0031ba249
img_002.jpg : b33d9d4ac0245e2306138c3980c214e5
img_003.jpg : de53f145027d4f2dfa653f4b5fc140dc
img_004.jpg : d49abf09861b060e0bd8854dfcd0e95c
img_005.jpg : d8e8fca2dc0f896fd7cb4cb0031ba249
img_006.jpg : 2fff7fcee8dfe9cadd122fb407448252
img_007.jpg : d8e8fca2dc0f896fd7cb4cb0031ba249
img_008.jpg : 5bcf849463c2c78ebfb1ebd88efc25cf
img_009.jpg : d8e8fca2dc0f896fd7cb4cb0031ba249
img_010.jpg : d8e8fca2dc0f896fd7cb4cb0031ba249

I think there are many better ways, but I think I'd do this


2022-09-20 20:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.