detecting/establishing a pppoe connection

couzteau

Registered
hello,

i would like to automatically detect if my computer is connected to the interrnet via pppoe and connect it if it isn't. this should be accomplished using a shell script that i can run with cron.

actually finding out if the connection exists is quite easy:

#!/bin/sh
ifconfig -a | grep ppp0 | grep blabla

but who do i establish it via shell script???

thanks for your advice.

couzteau
 
i 've totally fogotten about applescript. this definitely the easiest way to get this done.

all you need to do is save the following line with script editor as a executable applescript.

tell application "Internet Connect" to connect configuration "pppoe"

you can can run this from the command line with cron or put it into an idle loop in as to always stay online

check the the final version below
 
i run the perl-script below called iConnect.pl with cron. like this i check every 30 minutes if my pppoe connection is alive. if not it will be established immediately.

save this as iConnect.pl and make it executable (chmod 755 iConnect.pl)
#!/usr/bin/env perl
$IFCONFIG=`/sbin/ifconfig -a`;
$CONNECT=1;
@LS =split(/\x0a/, $IFCONFIG);
for $l(@LS){
$CONNECT=0 if $l=~m/ppp0/
}
system("open /Users/me/Documents/Scripts/iConnect") if $CONNECT;
the applescript iConnect contains just a single line:
tell application "Internet Connect" to connect configuration "pppoe"

and resides in
/Users/me/Documents/Scripts/
the crontab is installed using the command crontab -e
it should contain something like (make sure the line is terminated with a newline)
0,30 * * * * /Users/jochenha/Documents/Scripts/iConnect.pl
this checks every 30 minutes every day.

cheerz
 
as i just found out there is no need for two scripts. you can execute applescript via perl.

my script now looks like this:
#!/usr/bin/env perl

$IFCONFIG=`/sbin/ifconfig -a`;
$CONNECT=1;
@LS =split(/\x0a/, $IFCONFIG);
for $l(@LS){
$CONNECT=0 if $l=~m/ppp0/;
}
if($CONNECT){
system("osascript -e 'tell application \"Internet Connect\" to connect configuration \"Ethernet (integriert)\"'");
system("osascript -e 'tell application \"Internet Connect\" to quit'");
}

all i need is to run this script with cron. additionally this script now quits Internet Connect after establishing a connection.

does anybody know a better way to run applescript from perl?

cheerz
 
I know this is an old thread, but your replies are not working with me. This line of code gives me error #4:
tell application "Internet Connect" to connect configuration "pppoe"

If I only put
tell application "Internet Connect" to connect
nothing happens...
 
You have to have a configuration called "pppoe" in Internet Connect. Open the internet connect and change your default connection to "pppoe" or change that part of the script to whatever your default connection is. So:

Code:
tell application "Internet Connect" to connect configuration "[put your connectioni name here]"
 
Back
Top