【问题标题】:Having problems with a shell script for manipulating and uploading images to my webserver用于操作图像并将图像上传到我的网络服务器的 shell 脚本出现问题
【发布时间】:2012-01-11 18:20:39
【问题描述】:

我知道这很脏,绝对不是最好的方法。我拼凑了一堆不同的脚本来尝试完成这项工作,但我不断收到“convert.sh:24:Bad Substitution”错误。也许有人可以帮我清理它并让它工作。谢谢。

#!/bin/bash

rm -v -R temp/
mkdir temp
mkdir temp/raw

DIR="/media/mdrive/dump/"

if [ -z "$DIR" ]; then
    echo >&2 "Syntax: $0 <directory>"
    exit 1
fi

if [ ! -d "$DIR" ]; then
    echo >&2 "\"$DIR\" is not a directory"
    exit 1
fi

cd "$DIR"

for file in *.jpg *.JPG; do
    first=${file::1}
    mkdir -p $first && mv $file $first/;
done

cp -v -R /media/mdrive/dump/* /media/mdrive/stagingForUpload/
cp -v -f -R /media/mdrive/dump/* /media/mdrive/original/
cp -v -R /media/mdrive/dump/* temp/raw/
rm -v -R /media/mdrive/dump/*

# Creates directories
mkdir temp/images
mkdir temp/medium
mkdir temp/large

# Copies ~/Desktop/raw into ~/Desktop/small, medium & large
cp -v -R temp/raw/* temp/images/
cp -v -R temp/raw/* temp/medium/
mv -v temp/raw/* temp/large/
rm -v -R temp/raw/

# Converts images into respective size and quality
find temp/images/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 100x100">" -quality 80 -compress JPEG -monitor -strip
find temp/medium/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 428x270"^" -quality 80 -compress JPEG -monitor -strip
find temp/medium/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 428x270">" -quality 80 -compress JPEG -monitor -strip
find temp/large/* -maxdepth 2 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 800x800">" -quality 85 -compress JPEG -monitor -strip -gravity SouthEast -draw 'text 10,10 "www.kmstools.com"'

#Batch Renames
find temp/medium -iname "*.jpg" -printf 'mv %p %p\n' | sed 's/\.jpg$/_MED\.jpg/' | while read l; do eval $l; done
find temp/large -iname "*.jpg" -printf 'mv %p %p\n' | sed 's/\.jpg$/_LRG\.jpg/' | while read l; do eval $l; done

# Consolidates images into image directory
mv temp/large temp/images
mv temp/medium temp/images

# Removes Thumbs.db
find temp/images/ -type f -iname Thumbs.db | while read FILE ; do rm "${FILE}" ; done

# Copies images/ to website_directory_structure
cp -v -R temp/images/* /media/mdrive/website_directory_structure/

# Uploades files to Old KMS Webserver
ncftpput -m -R -F -u <username> -p <password> <webserver>.com /public_html/images/ temp/images/

【问题讨论】:

  • 您是否使用-x 运行它以查看究竟是哪一行给了您错误?
  • 第 24 行似乎是问题
  • 嗯,这显然不是一个糟糕的替代。使用-x 运行它会让您更准确地了解它是如何计算行数的。
  • 试图将代码粘贴到此评论中至少可以说令人沮丧
  • line 1 + set -e line 2 + rm -v -R temp/ line 3 移除目录: temp/raw' **line 4** removed directory: temp' line 5 + mkdir temp line 6 + mkdir temp/raw line 7 + DIR=/media/mdrive/dump 第 8 行 + [ -z /media/mdrive/dump ] 第 9 行 + [ ! -d /media/mdrive/dump ] line 10 + cd /media/mdrive/dump line 11 convert.sh: 25: 错误替换

标签: bash imagemagick mogrify


【解决方案1】:

在脚本中寻找唯一的替代品怎么样? ;-)(是的,它在第 22 行!)

您要么需要使用/bin/bash,要么找到其他方法来提取单词的第一个字母...

【讨论】:

  • 我真的很擅长这个。你能举个例子让我明白你的意思吗?
  • 我的错,我假设您在脚本的第一行中使用了#!/bin/sh,因为它在我的系统上与#!/bin/bash 配合得很好。你确定你真的在你的实际脚本中使用#!/bin/bash 吗?如果没有任何帮助,请尝试将第 22 行 (first=${file::1}) 替换为类似 first=$(echo "$file" | cut -b -1) 的丑陋替代品
猜你喜欢
  • 2012-02-29
  • 1970-01-01
  • 2019-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-22
  • 1970-01-01
相关资源
最近更新 更多