分页: 1 / 1

帮忙改一下脚本 :)

发表于 : 2011-08-03 0:09
iblicf

代码: 全选

#!/bin/bash

function usage {
        echo "Usage: $(basename $0) <filename>
Upload an image to xxxxx.me and output its URL to stdout.
If xsel or xclip is available, the URL is put on the X selection for easy pasting." >&2
}

if [ $# != 1 ]; then
        echo "No file specified" >&2
        exit 1
elif [ ! -f "$1" ]; then
        echo "File \"$1\" not found" >&2
        exit 1
fi

# check for curl
which curl >/dev/null 2>/dev/null || {
        echo "Couln't find curl, which is required." >&2
        exit 1
}

# upload the image
response=$(curl -F "uploadfile=@$1" "http://xxxxx.me/index.php?type=uploadv3&key=QT5LGz7ktGFVZpfFArVHCpEvDcC3qrUZrf0kP" 2>/dev/null)
if [ $? != 0 ]; then
        echo "Upload failed" >&2
        exit 2
fi

# parse the response and output our stuff
status=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f1 | cut -d: -f2)
if [ $status != 1 ]; then
        echo "Some sort of error occurred" >&2
        exit 1
fi
img=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f2 | cut -d: -f2)
ext=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f3 | cut -d: -f2)

file="$img.$ext"
url="http://xxxx.me/$file"

echo $url


这个是给图床传图的,返回一个图片连接地址,目前只支持单张传 ~~ 希望能支持多张,比如 img.sh *.png

或者给一个参考类似的 shell 脚本 ~~ 多谢

Re: 帮忙改一下脚本 :)

发表于 : 2011-08-03 10:53
eexpress
curl提交啊。curl不熟悉。
perl的 WWW::Mechanize 的。要不。

Re: 帮忙改一下脚本 :)

发表于 : 2011-08-03 12:01
link_01
[bash]
#!/bin/bash

usage() {
echo "Usage: $0 <filename>
Upload an image to xxxxx.me and output its URL to stdout.
If xsel or xclip is available, the URL is put on the X selection for easy pasting."
}

# check for curl
which curl >/dev/null 2>&1 || {
echo "Couln't find curl, which is required."
exit 1
}

upload() {
# upload the image
response=$(curl -F "uploadfile=@$1" "http://xxxxx.me/index.php?type=uploadv3 ... 3qrUZrf0kP" 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Upload failed"
exit 1
fi

# parse the response and output our stuff
status=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f1 | cut -d: -f2)
if [ $status != 1 ]; then
echo "Some sort of error occurred"
exit 1
fi
img=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f2 | cut -d: -f2)
ext=$(echo $response | sed 's/[\"\{\}\[\]]*//g' | cut -d, -f3 | cut -d: -f2)

file="$img.$ext"
url="http://xxxx.me/$file"

echo $url
}

if [ $# -lt 1 ]; then
usage; exit 1
fi

for i in $@; do
if [ -f $i ]; then
upload $i
else
echo "file $i is not found!"
fi
done
[/bash]
原来能用的话,扩展下参数,你自己再改改吧。