Written a bash script that generates thumbnails, not the nicest but it works:
#!/bin/bash
export DISPLAY=localhost:2.0
function clean_string () {
CLEAN=${1//_/};
CLEAN=${CLEAN// /_};
CLEAN=${CLEAN//[^a-zA-Z0-9_]/};
}
for line in $(cat /var/www/le_file.txt); do
clean_string "$line"
FILENAME=$CLEAN;
echo "site: $line";
`/usr/local/bin/khtml2png2 --width 1024 --height 768 --time 10 --disable-java --disable-plugins $line /var/www/$FILENAME.png &`;
done
When khtml2png cant find a site it crashes:
terminate called after throwing an instance of 'DOM::DOMException' and the script doesn't continu.
How can I advance the script when an error occurs? I thought of something like:
try {
`/usr/local/bin/khtml2png2`
}
catch() {
}
UPDATE see for output: http://img833.imageshack.us/img833/144/bashscript.png
Thanx in advance,
Johan
Recall that
$( cmd ... )AND ` cmd ` are for command substitution, where the output of one command is substituted into the current line of script, i.e.means what will be executed is
(not a great example ;-()
As you are already using
$( cat .... )please realize that backticks (as you have around /usr/local/bin/khtml2png2 and$( /usr/local/bin/khtml2png2 ...)are equivalent.Yes, your command gets executed using cmd-substition, but the shell will try to interpret any output from the cmd-subst. As your headline is ‘bash continue on err’, I think a sub-shell is what you need.
I’m assuming that you want to isolate any failures of khtml2png2 and allow the script to try again and hence command substitution. The more typical approach is use a sub-shell and surround your process like
( ... khtml2png2 ... ).But then what is your intent having the ‘&’ char at the end? It looks like you intend for khtml2png2 to run in the background.
So, inside your
for line ...loop, use eitherwhich will cause each invocation of khtml2png2 to run until it is done AND then cycle through the loop to the next value for ${line}.
OR
will launch as many copies of
khtml2png2as there are lines in/var/www/le_file.txt, all running in the background, competing with each other for CPU. (I don’t know how long each invocation ofkhtml2png2takes to run, seconds or minutes?) Maybe not what you want if there are more than 5-10 lines of text.If this doesn’t give you some answers to work with, please edit your question above to indicate your intent, why you need cmd-sub, and running in the background.
Finally, when you do need to use command substitution, back-ticks are only for super-compatibility with the Bourne shell found on older Unix and not Linux systems. They are considered deprecated and you should use
$( .. cmd )form of command substitution.I hope this helps.