views:

670

answers:

3

I have a bash script mystuff containing a line like

lynx -dump http://example.com >tmpfile

and the script works fine, including this part, except when I run it non-interactively:

$ ./mystuff &
[1] 3712
$ jobs
[1]+ Stopped

The job is stopped. I find that lynx is the culprit. Even running this command directly from the bash prompt causes the job to be stopped immediately:

$ lynx -dump http://example.com >tmpfile &
[1] 1836
$ jobs
[1]+ Stopped

Why won't lynx run in the background? How can I fix this?

EDIT:

I am using lynx because I don't want to have to parse the raw HTML. The difference between wget and lynx -dump is that lynx will render the HTML; it will hide all the tags, arrange text nicely, etc.

+1  A: 

Not the answer you are lookign for but could you just use wget instead?

Martin Beckett
+1 , certainly use wget.
Aiden Bell
+2  A: 

Lynx wants to talk to your terminal, but can't, so it does a SIGSTP (tty input) and waits for you to foreground the process.

As mgb said above: use wget. wget -O tmpfile http://example.com does the same thing as what you're doing with lynx above.

Josh K
Is there a way to fake the tty, or redirect it? I know I can use -term=ansi (for instance) to force the terminal type.
system PAUSE
Is there a particular reason you must use lynx? Are you trying to take advantage of the fact that lynx will render the page in a text mode? On my system `w3m -dump` works properly without causing a STOP signal.
Josh K
I was not aware of w3m, thanks! I've checked and it looks like it will work. I appreciate the explanation and the workaround.
system PAUSE
A: 

On my system, your lynx command works as is. Try this and see what happens:

lynx -dump -term=xterm http://example.com >tmpfile &
Dennis Williamson