ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have the following script i am writing to convert and move some files after an upload...
The first part of renaming the files works ok but then it does not get to the conversion part
can anyone point out what i am missing?
tia
#!/bin/bash
#####################################################################
# setup variables
#####################################################################
IMAGEDIR='/home/image/convert'
DATE=`date +%m-%d`
JPG='/usr/local/apache/htdocs/imagegallery/admin/mainimages/tmp/'
TIF='/usr/local/apache/htdocs/imagegallery/admin/mainimages/'
ERRORS='/tmp/errors'
LIST='/tmp/list'
RESULTS='/tmp/results'
CONVERTED='/tmp/converted'
#####################################################################
# Convert files and log actions
#####################################################################
#
# Create three files - error, list and results.
#
# list = file listing of all files converted that day (size and name)
# errors = errors generated by conversion
# converted = output of file conversion
# results = results or errors of the conversion process
#
#
#####################################################################
cd ${IMAGEDIR}
# Rename files with spaces - replace the spaces with a _
#
find ${IMAGEDIR} -name '* *' -type f | sort | while read FILE
do
NEWFILE=`dirname "${FILE}"`/`basename "${FILE}" | sed 's/ /_/g;'`
mv "${FILE}" "${NEWFILE}"
#
# Populate list of files > generated each time and cleaned out at the end of the daily script
ls -lh ${IMAGEDIR} | awk ' { print $9 " " $5 } '>>$LIST
#
for files in ${IMAGEDIR}
do
(
echo converting ${files} >>$CONVERTED
#
# echo output from conversion to converted log file/convert the files/move the files and set permissions
#
echo "convert ${files} -resize 800x600 -colorspace rgb ${files}.jpg >>$CONVERTED 2>&1"
#
# mv files to web space and set permissions (echo put in for testing)
#
echo "mv ${files} ${TIF}${files}_${DATE}.tif"
echo "mv ${files}.jpg ${JPG}${files}_${DATE}.jpg"
echo "cd ${TIF}"
echo "chown nobody:nobody *.tif"
echo "chmod 664 *.tif"
echo "cd ${JPG}"
echo "chown nobody:nobody *.jpg"
echo "chmod 664 *.jpg"
)
done
#
# Generate Result section (Part 4)
#
#
cat $CONVERTED |egrep "converting|error" >>$RESULTS
#
# Generate Errror section (Part 5)
#
cat $RESULTS |egrep "error|delegate" |awk ' { print $ 2 }' >>$ERRORS
#
cat /dev/null >$CONVERTED
cat /dev/null >$LOGFILE
could you explain what that statement means please?
(can't use it but i'm curious :-)
also , $LIST is also populated throughout the day as a master list of what files were changed that day. It will contain more that what is in the IMAGEDIR as conversions happen from other locations..
I need to be able to say for files in the $IMAGEDIR do ..... but i'm not sure how to specify the files in the directory..
not sure of the syntax for it, i need to convert only the files...
also, do you know how i would pause between the first commands that search and rename the files if they contain spaces before moving onto the conversion? As i test it is not waiting for this process to complete, the files with the spaces in their names then crap out when i try to move them...
The difference is that characters like * and ? are expanded by the shell to make them match with the contents of your file system. The rules involved are called globbing and take place after the IMAGEDIR variable is substituted for its value.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.