Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Run a script when PPP is started or stopped Network
I recently discovered that if you have a script located at /etc/ppp/ip-up then it will get called every time a PPP connection is started. Similarly, if you have a script at /etc/ppp/ip-down then it will get called every time the connection goes down. It is important that the execute bit is set on the script, and you proabably have to be root to create and save the file. Here's how to set the execute bits on the two scripts:
chmod a+x ip-up
chmod a+x ip-down
I use it to start and stop fetchmail (pop-smtp mailing software). But by using 'open', you could probably do anything. A word of caution: It may be running stuff as root so a sudo username whatevercommands might be useful.

[Editor's note: I don't have a PPP connection, so I can't test this...]
  • Currently 3.40 / 5
  You rated: 3 / 5 (5 votes cast)

Run a script when PPP is started or stopped | 10 comments | Create New Account
Click here to return to the 'Run a script when PPP is started or stopped' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
no script in /etc/ppp
Authored by: sungwoo on Nov 25, '01 02:07:38PM

I check the /etc/ppp, it's empty...
Could you post or send those script please?

[ Reply to This | # ]
Must create script
Authored by: Anonymous on Nov 26, '01 09:11:13PM
You have to create the scripts. They don't exist otherwise.

Create a new file in BBEdit or another editor.
Make sure the top line says
and then follow that with the commands you want to execute each on its own line

Save it as ip-up then copy it to the correct location with

sudo cp ip-up /etc/ppp/

Then type in your password when prompted.

Then type
sudo chmod a+x /etc/ppp/ip-up

Similarly for ip-down

[ Reply to This | # ]
How about scripting the PPP login?
Authored by: sjonke on Nov 25, '01 06:02:52PM

That's what I need. My ISP, which is really inexpensive ($8 a month), unfortunately uses a login that isn't the norm. In OS 9 it was possible to "record" the login process and then use that to automate the login but this seems to be gone in OS X. Is there any way to script the login so that I no longer have to manually type in my username, password and connection type every time I dial in?

[ Reply to This | # ]
Works great
Authored by: alienrat on Nov 26, '01 03:20:44PM
I was looking for a way to do this as my isp said I was logged on longer then I actualy was. I wrote some scripts just to make a log of when it went up and down:
#!/bin/sh -
dstore=`date +%y/%m/%d::%H:%M:%S`
echo "ppp up - $dstore" >> /var/ppp.log
and now I have this nice growing logfile of when I was connected. All I need to do then is a nice little cocoa program to read/process the file Thanks for that tip

[ Reply to This | # ]
Authored by: unimatrixzxero on Aug 10, '05 05:43:03AM

How about making a widget that would read that file :)

[ Reply to This | # ]
Ahh.. thanks. =) (no contents)
Authored by: sungwoo on Dec 01, '01 07:39:17PM


[ Reply to This | # ]
These are great
Authored by: Xeo on Feb 03, '02 10:47:52PM

I'm using ip-up for two functions and ip-down for one. ip-up first uses curl to contact my dynamic DNS provider to update my domain with my new IP. The second function is to log the connection time and IP address to a file. The only function of the disconnect is to log the time it was disconnected to the same file.

I found these variables which are passed to ip-up. They make it very easy to log or use the information to get things done.

When the ppp link comes up, this script is called with the following
$1 the interface name used by pppd (e.g. ppp3)
$2 the tty device name
$3 the tty device speed
$4 the local IP address for the interface
$5 the remote IP address
$6 the parameter specified by the 'ipparam' option to pppd

If you wanted to log the time and IP to a log file, for example, you could use this line in your script:

echo `date` -- Connected -- IP Address: $4

That's very close to my own line except I formated my date differently than the default.

[ Reply to This | # ]
Problem executing /etc/ppp/ip-up
Authored by: schroeder64 on Sep 15, '02 10:22:05AM

I created the ip-up shell script with execute permission, but pppd is giving me the following error:

Sep 15 09:52:22 pppd[828]: Can't execute /etc/ppp/ip-up: Exec format error

It seemed that it was expecting a binary program instead of script. To test it out I tried to link /bin/ls to /etc/ppp/ip-up, and pppd didn't show an error.

I did this on 10.2.

[ Reply to This | # ]
Good for sendmail
Authored by: geoffsaulnier on Feb 11, '02 06:30:50AM

Yep - Good tip. I use Demon as an ISP here in the UK. They give you a node which means that every user gets an email address in that domain that is like or

Sendmail wouldn't download mail from there properly because, if it started with the box, there was no resolv.conf so it couldn't resolve its address and couldn't figure out how to talk to Demon's DNS servers when I connected using PPP.

Now, I start sendmail with ip-up and stop it with ip-down and it works great!!


[ Reply to This | # ]
Run a script when PPP is started or stopped
Authored by: BrianSchott on Jun 22, '02 09:35:10AM

I use a modem to connect with my University server via Internet Connect. After the dialtone is accepted a miniature "Terminal" window appears and waits for me to enter a series of 4 values to validate me as a user. Each of the 4 values is preceded by a distinct prompt. For example, the first prompt ends with " Alias: ". Under system 9 I was able to use a script provided by the University (listed below) to automate this process, but I have not been able to activate the script in OS X.

One of the ways I have tried to accomplish the automation is to follow the example provided by Angus Hardie on Nov 25, 01. I have placed the following text into the file /etc/ppp/ip-up as suggested and have changed the permissions "chmod a+x ip-up". This does not seem to work; no acknowledgement of the script ip-up appears: I still must enter info manually. Do you have any recommendations, please?


First part of Script follows:

MATCHSTR 1 11 " Alias: "
NOTE "Connect script couldn't match \34 Alias: \34" 3
IFSTR 11 12 "<Guest>"
IFSTR 11 12 ""
WRITE "^u\13"
ASK 0 "Please enter name: "
WRITE "^*\13"
MATCHSTR 1 14 "Password: "
NOTE "Connect script couldn't match \34Password: \34" 3

[ Reply to This | # ]