[R] Test internet presence

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Mon Sep 11 15:30:26 CEST 2006


[Sorry -- errors due to mistyping especially at ">>>" below.
 Corrected in the following lines.]

On 11-Sep-06 Ted Harding wrote:
> On 11-Sep-06 Gregor Gorjanc wrote:
>> It seems that 'internal' method was used (I use R 2.3.1 under
>> Linux) as indicated in help page of download.file. I could
>> use wget or lynx methods, but these two must be available,
>> so this is not really portable. Are there any other options
>> for testing internet access? I am thinking that this might be
>> more relevant for R-devel. I will wait a bit
>> before moving there.
>> 
>> -- 
>> Lep pozdrav / With regards,
>>     Gregor Gorjanc
> 
> Hi Gregor,
> Since you are using Linux, I think you should ask R to delegate
> the test to the system.
> 
> If you have a script, in executable file ("755") say "test.inet.sh",
> which says something like

  if ping -c 1 <something> ; then
      export NET_UP="YES"
    else
      export NETP_UP="NO"
  fi

> where "<something>" is the IP address or name of an external host
> which responds to 'ping' (some will not, depending on their firewall
> settings), then you can use on R:
> 
> >>> system("test.inet")
> >>> if( sys.getenv(NET_UP") == "YES" ) { ... } else { ... }

system("test.inet.sh")
if( sys.getenv("NET_UP") == "YES" ) { ... } else { ... }

> For example (nothing to do with R, but shows the principle),
> I have the following script to set my system time and hardware
> clock from whichever one of 3 NTP servers is willing to respond:
> 
> if /bin/ping -c 1 ntp0.zen.co.uk ; then
>     export NETTIME="/usr/sbin/ntpdate -u ntp0.zen.co.uk"
>   elif /bin/ping -c 1 ntp2b.mcc.ac.uk ; then
>     export NETTIME="/usr/sbin/ntpdate -u ntp2b.mcc.ac.uk"
>   elif /bin/ping -c 1 ntp2c.mcc.ac.uk ; then
>     export NETTIME="/usr/sbin/ntpdate -u ntp2c.mcc.ac.uk"
>   else
>     export NETTIME=""
> fi
> if [ "$NETTIME" != "" ] ; then
>   sleep 1
>   sleep 1
>   $NETTIME
>   /sbin/clock -u -w
>   date
> fi
> 
> 
> which also illustrates how to allow for the possibility that
> the "default" server might not be responding at the time, so
> it has 2 fallback servers.
> 
> Hoping this helps,
> Ted.
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 11-Sep-06                                       Time: 13:42:22
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 11-Sep-06                                       Time: 14:28:11
------------------------------ XFMail ------------------------------



More information about the R-help mailing list