1

I have a bash script that executes a web-based php script using lynx, then the browser stays active allowing the user to input commands. I would like to automate quitting lynx and continuing with the rest of the script.

In the script I have:

lynx "https://www.domain.com/script.php?"
[rest of script]

Is there a way to output a q followed by a y so the script will continue without needing input from the keyboard?

Zanna
  • 69,223
  • 56
  • 216
  • 327
Don
  • 229
  • 1
  • 3
  • 16
  • 4
    Post your script and explain why you are using lynx for this task and what interaction / input you need / anticipate from a user running the script – Panther Jun 22 '17 at 16:57
  • I don't necessarily need lynx though i'm running it from within a vagrant vm so it seems to be the easiest working solution (firefox & chrome would need to be installed & configured from within the vm) that i'm aware of. Once the web-based script is complete I want to (q)uit & confirm (y) and continue the script. This will always be the input, just trying to automate it. – Don Jun 22 '17 at 17:01
  • 3
    Why lynx and not curl or wget? – muru Jun 22 '17 at 17:26
  • 1
    @sudodus check which post you edited :) – muru Jun 22 '17 at 17:42
  • 1
    @muru using curl is actually the simplest solution and avoids other users having to install lynx. I marked the answer below as it answers this specific question. Thanks. – Don Jun 22 '17 at 17:56
  • I removed my answer, because there were better solutions – sudodus Jun 22 '17 at 17:58

1 Answers1

1

Use the -dump argument.

Example of lynx in a script:

#!/bin/bash

buffer=$(lynx -dump "https://www.domain.com/script.php?")

copyright=$(echo "$buffer"|egrep Copyright)
phonenumber=$(echo "$buffer"|egrep "]Call.*Chat"|awk '{print $5}')

echo -e "This domain has this Copyright notice:\n$copyright"
echo "Phone contact is: $phonenumber"

Running the above tested script will give this output:

$ ./script.sh
This domain has this Copyright notice:
   © Copyright  2017 Domain.com. All rights reserved.
Phone contact is: 800-403-3568
L. D. James
  • 24,768
  • 10
  • 68
  • 116