curl与shell脚本结合使用实例

#!/bin/bash
# Zip coco folder
# zip -r coco.zip coco
# tar -czvf coco.tar.gz coco
# cur利用URL规则在命令行下工作的文件传输工具;url下载工具
# Download labels from Google Drive, accepting presented query
filename="coco2017labels.zip"
fileid="1cXZR_ckHki6nddOmcysCuuJFM--T-Q6L"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
#-c 操作结束后把cookie写入这个文件 -s静音模式步输出任何东西
#> /dev/null把标准输出定向到/dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}
#-b cookie字符串或文件读取位置 -L会让HTTP请求跟随服务器重定向 
# -o 把输出写入该文件,即-o之前都是获取下载的东西,
#awk文本分析命令,表达式由单引号包含,
#NF表示字段数,
rm ./cookie
#get coco2017labels.zip in cureent folder
# Unzip labels
unzip -q ${filename}  # for coco.zip
# tar -xzf ${filename}  # for coco.tar.gz
rm ${filename}
#解压并删除coco2017labels.zip
# Download and unzip images
cd coco/images
f="train2017.zip" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f
#进入目录下载train解压并删除
f="val2017.zip" && curl http://images.cocodataset.org/zips/$f -o $f && unzip -q $f && rm $f

# cd out
cd ../..

猜你喜欢

转载自blog.csdn.net/qq_42698422/article/details/106683897