#!/bin/bash # 图片自动压缩 echo '= start ============================================' find ./src/assets -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' |while read IN_FILE;do { UA='User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' while set $(dd if=/dev/urandom bs=4 count=1 2>/dev/null | od -An -tu1) [ $1 -lt 224 ] && [ $1 -ne 10 ] && { [ $1 -ne 192 ] || [ $2 -ne 168 ]; } && { [ $1 -ne 172 ] || [ $2 -lt 16 ] || [ $2 -gt 31 ]; } do :; done IP="X-Forwarded-For:$1.$2.$3.$4" echo "压缩: $IN_FILE" JSON=`curl -s --data-binary @$IN_FILE -H "$UA" -H "$IP" https://tinypng.com/web/shrink` URL=`echo $JSON|awk -F 'url":"' '{print $2}'|awk -F '"' '{print $1}'` if [ -n "$URL" ];then echo "JSON: $JSON" echo "保存: $URL->$IN_FILE" curl -s $URL --output $IN_FILE else echo "异常: $JSON" fi }& done wait echo '= end ============================================'
标签:URL,tinypng,ne,echo,JSON,sh,FILE From: https://www.cnblogs.com/zhenjianyu/p/17018467.html