Sample Header Ad - 728x90

Raspbian running headless doing scripted procedures on a internet page using text browser

0 votes
2 answers
413 views
I am somewhere between a new and intermediate linux user. I am setting up a local network for a small group, and I need to configure an automatic sign-in to a webportal when internet connectivity is lost. I have this working when I run my bash script with a monitor on the raspberry (RASPBIAN OS) itself, the sequence of things are: Check if internet is down with fping --> Open xterm --> have xdotool open w3m and automate the clicks and inputting password. Here is my code in condensed form: DNSPing=$(fping 9.9.9.9) EtecsaPing=$(fping 10.180.0.30) ... if [[ ( $EtecsaPing == "10.180.0.30 is alive" ) && ( $DNSPing == "9.9.9.9 is unreachable" ) ]] then echo "ETECSA UP - Internet all down - Run login script now" xterm & sleep 2 xdotool type "w3m -m https://10.180.0.30:8443/ " xdotool key Return ... xdotool type xdotool key Return xdotool sleep 1 ... xdotool key Return xdotool type xdotool sleep 1 ... xdotool key Return sleep 5 killall xterm fi So when I connect a monitor and mouse and run this it works just fine. I want to have this running headless and with the script in crontab, and after 2 days of trying I feel like I'm just going in circles. The problem is that both the new xterm session and xdotool requires a DISPLAY defined to run. To that end I have installed xvfb which creates a simulated display. sudo Xvfb :10 -ac -screen 0 1024x768x24 DISPLAY=:10 xterm & (the script from above) That runs without any errors, but it also does not work. If I run: sudo Xvfb :10 -ac -screen 0 1024x768x24 DISPLAY=:10 xterm -e "echo 'deb blah ... blah' | sudo tee -a /CronJobs/yap.txt > /dev/null" It adds the echo to the file, so I know that my display is running the xterm session, and I conclude the simulated display and xterm session is all working. If I do: sudo Xvfb :10 -ac -screen 0 1024x768x24 DISPLAY=:10 xterm & DISPLAY=:10 xdotool type "sudo echo 'deb blah ... blah' | sudo tee -a /CronJobs/yap.txt > /dev/null" DISPLAY=:10 xdotool key Return It does not work. In conclusion, xdotool is working (no errors), but not doing anything! So I'm thinking xdotool is not typing into the xterm terminal because the window is not selected, and I try to select the xterm window and I get: DISPLAY=:10 xdotool getactivewindow Your windowmanager claims not to support _NET_ACTIVE_WINDOW, so the attempt to query the active window aborted. xdo_get_active_window reported an error And at this point my project is so unique that I can't find any good suggestions on what to do. A few people have tried to exchange the windowmanager for Xvfd but it's few and complicated. Put in simple words: - How can I make Xvfd act better like a real display? - Can I make the linux forget all about DISPLAY variables and windowmanager, and just unconditionally run the script as a normal user? How? - Can I automate my login sequence in a smarter way that would avoid xdotool? My network is private and I have no issue with solutions that can compromise the security on the raspberry, so disabling whatever xhost etc is fine, I just don't see how/what. Thanks in advance.
Asked by Lars Kuur (11 rep)
Nov 4, 2021, 10:44 PM
Last activity: Nov 6, 2021, 04:15 PM