How to login to website and auto-refresh page every X seconds from terminal?

0

I am trying to login to a particular website, then proceed to a particular page on that website and auto-refresh every X seconds.

Here's what I have so I can login:

curl --data "Username=xx&Password=xx&Login=Login" [url that login form submits]

Here's what I have to auto-refresh the web page:

while true; do wget -qO- https://www.website > /dev/null; sleep 60; done
  1. login to website
  2. go to page to be auto-refreshed
  3. auto-refresh every X seconds

How can I combine these codes (or similar functioning ones) so that they can carry out the task I need in a loop until cancelled with ie. CTRL + C?

Anonymous

Posted 2019-05-06T03:41:01.003

Reputation: 29

How is your question not its own answer? Just throw the quoted lines into a bash script, make it executable and execute it. – davidgo – 2019-05-06T04:03:02.517

In that case will you take the liberty of answering the question then please? When I attempt your suggestion it does not seem to function properly at all. I would appreciate it. Thanks. – Anonymous – 2019-05-08T16:24:13.827

What exactly happens when you put ot in tne script and run it? IE what is the error/how does it fail? – davidgo – 2019-05-08T19:55:40.330

There are many different outputs as I was never clear on how to run my pieces of code in the first place. – Anonymous – 2019-05-13T05:36:40.163

I can't work out what you are asking. Did you inherit those lines of code from someone else, and just following them exactly, or did you come up with them? Do you have an editor you can use? What are the outputs you are getting when you try run the script? – davidgo – 2019-05-13T05:45:55.727

I got them on this site from other questions but they do not work together, I wouldn't know how to do that. – Anonymous – 2019-05-13T10:12:56.520

Is there a better way to login to a site and auto refresh page to appear online? I am just trying to do this as a background process hidden (taking up as little system resources as possible) and running on every boot, and refreshing the page every 60 seconds or so. Thanks for your time. – Anonymous – 2019-05-13T10:14:34.357

Answers

0

The following wget code will make you appear to be online as long as you have your own cookie.txt file of when you were logged in. You can obtain a cookie.txt by pressing this extensions button while on the website you are trying to appear to be online. It will generate the cookie file to be used with the wget command.

https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg

This following code needs to be entered into bash terminal every 60 seconds, or however frequent you want the site to see that you have come online. I am currently running it within my crontab every 5 minutes. Most sites have a 5-10 minute timeframe of keeping you online within the system of the website, so this would only need to be ran once every 5-10 minutes, depending on the site and your personal preference.

wget -x --load-cookies ~/.config/cookies/website.txt "https://www.website.com/dashboard" >/dev/null

Anonymous

Posted 2019-05-06T03:41:01.003

Reputation: 29

1

The issue you are having relates to (a) using 2 different programs to log in and keep getting updates, and more relevantly (b) you are not keeping track of the session (ie using cookies).

CURL is generally considered more flexible and less abstracted then wget, so it would make sense to use this. Try creating a file along the following lines

#! /bin/bash

curl -b cookiejar.txt --data "Username=xx&Password=xx&Login=Login" '[url that login form submits]'

while true
do
     curl -b cookiejar.txt 'https://www.website...'  >/dev/null
     sleep 60
done

The above code might require a bit of massaging depending on your site, but the parts I tested worked for me on the site I tested. The magic is the "-b cookiejar.txt" on each line which links the login and subsequent connections (using the standard cookie/session mechanism built into the protocol).

Note the ' characters surrounding the https requests. This may be required so that the command line is not misinterpreted.

You will of-course, need to mark the file as executable - using a command like chmod 755 filename - to get it to run.

davidgo

Posted 2019-05-06T03:41:01.003

Reputation: 49 152