Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:45+00:00 2026-05-27T18:45:45+00:00

Written a bash script that generates thumbnails, not the nicest but it works: #!/bin/bash

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:45:45+00:00Added an answer on May 27, 2026 at 6:45 pm

    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.

    ls `echo foo`* 
    

    means what will be executed is

    ls foo*
    

    (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 either

      ( /usr/local/bin/khtml2png2 --width 1024 --height 768 --time 10 --disable-java --disable-plugins $line /var/www/$FILENAME.png )
    

    which 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

     /usr/local/bin/khtml2png2 --width 1024 --height 768 --time 10 --disable-java --disable-plugins $line /var/www/$FILENAME.png & 
    

    will launch as many copies of khtml2png2 as 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 of khtml2png2 takes 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following function in a bash script but it is not
I've written a script that uses associative arrays in bash (v 4). It works
I have a bash script that runs a simulation program written in Fortran 90,
I have written a simple script that calls a function in a while loop.
I have written a bash script that gets three paths based on input parameters
I've written a test script that I usually call from a cygwin bash. This
I've written a bash script that is doing exactly what I want it to
I have written a little bash script that reads commands (one per line), in
I've written a small script in bash that parses either the provided files or
I have written a bash script, A, that is calling another script, B, over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.