I am trying to make something which records my public ip address in a database, every few minutes.

I have already developed a web page which records the viewer's ip whenever loaded.

I would like to set up a cron job which will periodically load the page in the background. I know how to set up the cron job, but I don't know how to load a web page in the background from the command line.

How would you go about doing this?


Presumably, the page was developed so that the user agent doesn’t actually have to be a browser. If this is the case, you can simply use the curl command to fetch the page.

If you’re running it as a cron job, you don’t want the command to print any output. To do this use, the --silent option for curl and discard the HTTP response by redirecting the output to /dev/null. E.g., add the following cron job to fetch the page every 10 minutes:

*/10 * * * * curl --silent http://example.com/path/to/page curl >/dev/null

If you want to be more efficient, you could develop your web page so that it responds to a HTTP HEAD request as well as GET requests. That way, you could use curl -I so only HTTP headers are sent between the server and the client.

  • If I'm not wrong, curl only fetches the page, not executes it. How would you write a page that executes when being fetched? – ginkoid Apr 12 '17 at 13:03
  • @Ginkoid curl doesn't "execute a page" while browsers only execute client-side code, e.g., JavaScript (they "interpret" HTML/CSS to render a page). Clients sends a HTTP request and the server responds to that request. For static content (such as images or HTML documents), it simply responds with the contents of a file. For dynamic content, the server executes some code and then responds with the results of that program(s). I figure you're most likely running some sort of server-side code (e.g., PHP) to record the IP address. It's probably worth editing your question to clarify how you do this. – Anthony Geoghegan Apr 12 '17 at 13:55
  1. Select a programming language - Ruby, Python, Java or C#
  2. Write an instance of selenium webdriver, e.g. driver = Selenium::WebDriver.for :firefox
  3. Write the command to visit the URL, e.g. (Ruby) driver.get "http://www.google.com"
  4. Consider whether a direct GET would be better than using a browser

More info at http://www.seleniumhq.org/docs/03_webdriver.jsp#setting-up-a-selenium-webdriver-project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.